You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / resize

_ArrayFunctionDispatcher

numpy:resize

source: /numpy/_core/fromnumeric.py :1508

Signature

def   resize ( a new_shape )

Summary

Return a new array with the specified shape.

Extended Summary

If the new array is larger than the original array, then the new array is filled with repeated copies of a. Note that this behavior is different from a.resize(new_shape) which fills with zeros instead of repeated copies of a.

Parameters

a : array_like

Array to be resized.

new_shape : int or tuple of int

Shape of resized array.

Returns

reshaped_array : ndarray

The new array is formed from the data in the old array, repeated if necessary to fill out the required number of elements. The data are repeated iterating over the array in C-order.

Notes

When the total size of the array does not change reshape should be used. In most other cases either indexing (to reduce the size) or padding (to increase the size) may be a more appropriate solution.

Warning: This functionality does not consider axes separately, i.e. it does not apply interpolation/extrapolation. It fills the return array with the required number of elements, iterating over a in C-order, disregarding axes (and cycling back from the start if the new shape is larger). This functionality is therefore not suitable to resize images, or data where each axis represents a separate and distinct entity.

Examples

import numpy as np
a = np.array([[0,1],[2,3]])
np.resize(a,(2,3))
np.resize(a,(1,4))
np.resize(a,(2,4))

See also

ndarray.resize

resize an array in-place.

numpy.pad

Enlarge and pad an array.

numpy.repeat

Repeat elements of an array.

numpy.reshape

Reshape an array without changing the total size.

Aliases

  • numpy.resize