numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
resize(a, new_shape)

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.

Notes

When the total size of the array does not change ~numpy.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.

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.

Return a new array with the specified shape.

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.

Examples

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

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.sparse._lil.lil_matrix.resize scipy.sparse._coo.coo_matrix.resize scipy.sparse._compressed._cs_matrix.resize numpy.ma.core.resize scipy.sparse._base.spmatrix.resize scipy.sparse._dia.dia_matrix.resize scipy.sparse._dok.dok_matrix.resize

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/core/fromnumeric.py#1394
type: <class 'function'>
Commit: