
Is the zero-fill intentional? If so, it is documented? (NumPy 1.3)
Alan Isaac
a = np.arange(5) b = a.copy() c = np.resize(a, (5,2)) b.resize((5,2)) c # as expected
array([[0, 1], [2, 3], [4, 0], [1, 2], [3, 4]])
b # surprise!
array([[0, 1], [2, 3], [4, 0], [0, 0], [0, 0]])

On Wed, Mar 17, 2010 at 10:08 AM, Alan G Isaac aisaac@american.edu wrote:
Is the zero-fill intentional? If so, it is documented? (NumPy 1.3)
Alan Isaac
a = np.arange(5) b = a.copy() c = np.resize(a, (5,2)) b.resize((5,2)) c # as expected
array([[0, 1], [2, 3], [4, 0], [1, 2], [3, 4]])
b # surprise!
array([[0, 1], [2, 3], [4, 0], [0, 0], [0, 0]])
It is documented as in your example
numpy.resize(a, new_shape) Return a new array with the specified shape.
If the new array is larger than the original array, then the new array is filled with repeated copied of a. Note that this behavior is different from a.resize(new_shape) which fills with zeros instead of repeated copies of a.
Josef
NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

On 3/17/2010 10:16 AM, josef.pktd@gmail.com wrote:
numpy.resize(a, new_shape) Return a new array with the specified shape.
If the new array is larger than the original array, then the new array is filled with repeated copied of a. Note that this behavior is different from a.resize(new_shape) which fills with zeros instead of repeated copies of a.
Yes indeed. Sorry, I must have scrolled the help without realizing it, and this part was at the top.
So my follow up: why is this desirable/necessary? (I find it surprising.)
Alan

On Wed, Mar 17, 2010 at 8:42 AM, Alan G Isaac aisaac@american.edu wrote:
On 3/17/2010 10:16 AM, josef.pktd@gmail.com wrote:
numpy.resize(a, new_shape) Return a new array with the specified shape.
If the new array is larger than the original array, then the new array is filled with repeated copied of a. Note that this behavior is different from a.resize(new_shape) which fills with zeros instead of repeated copies of a.
Yes indeed. Sorry, I must have scrolled the help without realizing it, and this part was at the top.
So my follow up: why is this desirable/necessary? (I find it surprising.)
IIRC, it behaved that way in Numeric.
Chuck

A Wednesday 17 March 2010 22:56:20 Charles R Harris escrigué:
On Wed, Mar 17, 2010 at 8:42 AM, Alan G Isaac aisaac@american.edu wrote:
On 3/17/2010 10:16 AM, josef.pktd@gmail.com wrote:
numpy.resize(a, new_shape) Return a new array with the specified shape.
If the new array is larger than the original array, then the new array is filled with repeated copied of a. Note that this behavior is different from a.resize(new_shape) which fills with zeros instead of repeated copies of a.
Yes indeed. Sorry, I must have scrolled the help without realizing it, and this part was at the top.
So my follow up: why is this desirable/necessary? (I find it surprising.)
IIRC, it behaved that way in Numeric.
This does not mean that this behaviour is desirable. I find it inconsistent and misleading so +1 for fixing it.

On Wed, Mar 17, 2010 at 10:56 PM, Charles R Harris charlesr.harris@gmail.com wrote:
On Wed, Mar 17, 2010 at 8:42 AM, Alan G Isaac aisaac@american.edu wrote:
On 3/17/2010 10:16 AM, josef.pktd@gmail.com wrote:
numpy.resize(a, new_shape) Return a new array with the specified shape.
If the new array is larger than the original array, then the new array is filled with repeated copied of a. Note that this behavior is different from a.resize(new_shape) which fills with zeros instead of repeated copies of a.
Yes indeed. Sorry, I must have scrolled the help without realizing it, and this part was at the top.
So my follow up: why is this desirable/necessary? (I find it surprising.)
IIRC, it behaved that way in Numeric.
How would people feel about unifying the function vs. the method behavior ? One could add an addition option like `repeat` or `fillZero`. One could (at first !?) keep opposite defaults to not change the current behavior. But this way it would be most visible and clear what is going on.
Regards, Sebastian Haase

On 3/18/2010 4:56 AM, Sebastian Haase wrote:
How would people feel about unifying the function vs. the method behavior ? One could add an addition option like `repeat` or `fillZero`. One could (at first !?) keep opposite defaults to not change the current behavior. But this way it would be most visible and clear what is going on.
The current situation is confusing. I therefore hope that one of two things will happen.
- unification (probably with a `fill` option, with a default of None that produces the function's behavior but that can be give any numerical value (not just 0)), or - eliminate the method
Thanks, Alan
participants (6)
-
Alan G Isaac
-
Charles R Harris
-
Francesc Alted
-
Gael Varoquaux
-
josef.pktd@gmail.com
-
Sebastian Haase