[Numpy-discussion] bug in ndarray.resize?

josef.pktd@gmai... josef.pktd@gmai...
Wed Mar 17 09:16:20 CDT 2010


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
>


More information about the NumPy-Discussion mailing list