[Numpy-discussion] Inplace reshape
Charles R Harris
Mon Apr 23 13:04:02 CDT 2007
On 4/23/07, Keith Goodman <firstname.lastname@example.org> wrote:
> On 4/23/07, Christopher Barker <Chris.Barker@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
> Definition: numpy.reshape(a, newshape, order='C')
> Return an array that uses the data of the given array, but with a new
> - `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
> FORTRAN (column-major) order.
> - `reshaped_array` : array
> This will be a new view object if possible; otherwise, it will
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion