[Numpy-discussion] Inplace reshape

Keith Goodman kwgoodman@gmail....
Mon Apr 23 12:55:19 CDT 2007


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.


More information about the Numpy-discussion mailing list