dpnp.ndarray.shape
property
- property 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 of array dimensions to it. Unlike
dpnp.reshape, only non-negative values are supported to be set as new shape. Reshaping an array in-place will fail if a copy is required.For full documentation refer to
numpy.ndarray.shape.Note
Using
dpnp.ndarray.reshapeordpnp.reshapeis the preferred approach to set new shape of an array.See also
dpnp.shapeEquivalent getter function.
dpnp.reshapeFunction similar to setting shape.
dpnp.ndarray.reshapeMethod similar to setting shape.
Examples
>>> import dpnp as np >>> x = np.array([1, 2, 3, 4]) >>> x.shape (4,) >>> y = np.zeros((2, 3, 4)) >>> y.shape (2, 3, 4)
>>> y.shape = (3, 8) >>> y array([[ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.]]) >>> y.shape = (3, 6) ... TypeError: Can not reshape array of size 24 into (3, 6)