[Numpy-discussion] Inplace reshape
Charles R Harris
charlesr.harris at gmail.com
Mon Apr 23 14:04:02 EDT 2007
On 4/23/07, Keith Goodman <kwgoodman at gmail.com> wrote:
>
> On 4/23/07, Christopher Barker <Chris.Barker at noaa.gov> wrote:
> > reshape(...)
> > a.reshape(d1, d2, ..., dn, order='c')
> >
> > Return a new array from this one. The new array must have the same
> >
> > number of elements as self. Also always returns a view or raises a
> > ValueError if that is impossible.;
>
> Here's a better doc string that explains "This will be a new view
> object if possible; otherwise, it will return a copy."
>
> >> numpy.reshape?
> Type: function
> Base Class: <type 'function'>
> String Form: <function reshape at 0xb78894c4>
> Namespace: Interactive
> File:
> /usr/local/lib/python2.4/site-packages/numpy/core/fromnumeric.py
> Definition: numpy.reshape(a, newshape, order='C')
> Docstring:
> Return an array that uses the data of the given array, but with a new
> shape.
>
> :Parameters:
> - `a` : array
> - `newshape` : shape tuple or int
> The new shape should be compatible with the original shape. If an
> integer, then the result will be a 1D array of that length.
> - `order` : 'C' or 'FORTRAN', optional (default='C')
> Whether the array data should be viewed as in C (row-major) order
> or
> FORTRAN (column-major) order.
>
> :Returns:
> - `reshaped_array` : array
> This will be a new view object if possible; otherwise, it will
> return
> a copy.
>
> :See also:
> numpy.ndarray.reshape() is the equivalent method.
I think that it should raise an error, or warn, if it needs to make a copy,
but that isn't the tradition. Reshape does raise an error if the product of
the dimensions isn't the same for both the original and the reshaped array.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070423/e8a3ed23/attachment.html>
More information about the NumPy-Discussion
mailing list