dpnp.roll
- dpnp.roll(x, shift, axis=None)[source]
Roll the elements of an array by a number of positions along a given axis.
Array elements that roll beyond the last position are re-introduced at the first position. Array elements that roll beyond the first position are re-introduced at the last position.
For full documentation refer to
numpy.roll
.- Parameters:
a ({dpnp.ndarray, usm_ndarray}) -- Input array.
shift ({int, tuple of ints}) -- The number of places by which elements are shifted. If a tuple, then axis must be a tuple of the same size, and each of the given axes is shifted by the corresponding number. If an integer while axis is a tuple of integers, then the same value is used for all given axes.
axis ({None, int, tuple of ints}, optional) -- Axis or axes along which elements are shifted. By default, the array is flattened before shifting, after which the original shape is restored.
- Returns:
out -- An array with the same data type as x and whose elements, relative to x, are shifted.
- Return type:
dpnp.ndarray
See also
dpnp.moveaxis
Move array axes to new positions.
dpnp.rollaxis
Roll the specified axis backwards until it lies in a given position.
Examples
>>> import dpnp as np >>> x1 = np.arange(10) >>> np.roll(x1, 2) array([8, 9, 0, 1, 2, 3, 4, 5, 6, 7])
>>> np.roll(x1, -2) array([2, 3, 4, 5, 6, 7, 8, 9, 0, 1])
>>> x2 = np.reshape(x1, (2, 5)) >>> np.roll(x2, 1, axis=0) array([[5, 6, 7, 8, 9], [0, 1, 2, 3, 4]])
>>> np.roll(x2, (2, 1), axis=(1, 0)) array([[8, 9, 5, 6, 7], [3, 4, 0, 1, 2]])