numpy.ndarray.shape#
attribute
- ndarray.shape#
Tuple of array dimensions.
The shape property is usually used to get the current shape of an array,but may also be used to reshape the array in-place by assigning a tuple ofarray dimensions to it. As with
numpy.reshape, one of the new shapedimensions can be -1, in which case its value is inferred from the size ofthe array and the remaining dimensions. Reshaping an array in-place willfail if a copy is required.Warning
Setting
arr.shapeis deprecated and may be removed in thefuture. Usingndarray.reshapeis the preferred approach.See also
numpy.shapeEquivalent getter function.
numpy.reshapeFunction similar to setting
shape.ndarray.reshapeMethod similar to setting
shape.
Examples
>>>importnumpyasnp>>>x=np.array([1,2,3,4])>>>x.shape(4,)>>>y=np.zeros((2,3,4))>>>y.shape(2, 3, 4)
On this page