On 4/23/07, Keith Goodman <kwgoodman@gmail.com> 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
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