numpy.ndarray.resize

ndarray.resize(new_shape, refcheck=True, order=False)

Change shape and size of array in-place.

Parameters:

a : ndarray

Input array.

new_shape : {tuple, int}

Shape of resized array.

refcheck : bool, optional

If False, memory referencing will not be checked. Default is True.

order : bool, optional

<needs an explanation>. Default if False.

Returns:

None :

Raises:

ValueError :

If a does not own its own data, or references or views to it exist.

Examples

Shrinking an array: array is flattened in C-order, resized, and reshaped:

>>> a = np.array([[0,1],[2,3]])
>>> a.resize((2,1))
>>> a
array([[0],
       [1]])

Enlarging an array: as above, but missing entries are filled with zeros:

>>> b = np.array([[0,1],[2,3]])
>>> b.resize((2,3))
>>> b
array([[0, 1, 2],
       [3, 0, 0]])

Referencing an array prevents resizing:

>>> c = a
>>> a.resize((1,1))
...
ValueError: cannot resize an array that has been referenced ...

Previous topic

numpy.ndarray.reshape

Next topic

numpy.ndarray.transpose

This Page

Quick search