[Numpy-discussion] Bug in resize method?
Charles R Harris
Wed Aug 29 12:14:38 CDT 2007
On 8/29/07, Christopher Barker <Chris.Barker@noaa.gov> wrote:
> Charles R Harris wrote:
> > What *should* the resize method do? It looks like
> > it is equivalent to assigning a shape tuple to a.shape,
> No, that's what reshape does.
No, reshape returns a view and the view doesn't own its data. Totally
different behavior in this context.
> so why do we need it?
> resize() will change the SIZE of the array (number of elements), where
> reshape() will only change the shape, but not the number of elements.
> The fact that the size is changing is why it won't work if if doesn't
> own the data.
According to the documentation, the resize method changes the array inplace.
How can it be inplace if the number of elements changes? Admittedly, it
*will* change the size, but that is not consistent with the documentation. I
suspect it reallocates memory and (hopefully) frees the old, but then that
is what the documentation should say because it explains why the data must
be owned -- a condition violated in some cases as demonstrated above. I am
working on documentation and that is why I am raising these questions. There
seem to be some inconsistencies that need clarification and/or fixing.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion