[Numpy-discussion] Bug in resize method?
Charles R Harris
charlesr.harris at gmail.com
Wed Aug 29 12:28:21 EDT 2007
On 8/29/07, Stefan van der Walt <stefan at sun.ac.za> wrote:
> 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
> not be referenced by other arrays. Returns None.
The documentation is bogus:
>>> a = arange(6).reshape(2,3)
array([[0, 1, 2],
[3, 4, 5]])
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : False
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False
The reshaped array is a view on the original data, hence it doesn't
> own it:
> In : a = N.arange(6).reshape(2,3)
> In : a.flags
> 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.
This behaviour doesn't match documentation elsewhere, which is why I am
raising the question. What *should* the resize method do? It looks like it
is equivalent to assigning a shape tuple to a.shape, so why do we need it?
Apart from that, the reshape method looks like it would serve for most
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion