[Numpy-discussion] Bug in resize method?

Stefan van der Walt stefan at sun.ac.za
Wed Aug 29 11:58:57 EDT 2007


Hi Charles

On Wed, Aug 29, 2007 at 09:42:50AM -0600, Charles R Harris wrote:
> Hi all,
> 
> This looks like a bug to me.
> 
> >>> a = arange(6).reshape(2,3)
> >>> a.resize((3,3))
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ValueError: cannot resize this array:  it does not own its data

>From the docstring of a.resize:

    Change size and shape of self inplace.  Array must own its own memory and
    not be referenced by other arrays.    Returns None.

The reshaped array is a view on the original data, hence it doesn't
own it:

In [15]: a = N.arange(6).reshape(2,3)

In [16]: a.flags
Out[16]: 
  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False

> >>> a = arange(6).resize((2,3))
> >>> a
> 
> `a` has no value and no error is raised.

It is because `a` is now None.

Cheers
Stéfan



More information about the NumPy-Discussion mailing list