mindspore.numpy.roll

mindspore.numpy.roll(a, shift, axis=None)[源代码]

Rolls a tensor along given axes.

Elements that rolls beyond the last position are re-introduced at the first.

参数
  • a (Tensor) – Input tensor.

  • shift (Union[int, tuple(int)]) – 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 shift is an int while axis is a tuple of integers, then the same value is used for all given axes.

  • axis (Union[int, tuple(int)], optional) – Axis or axes along which elements are shifted. By default, the array is flattened before shifting, after which the original shape is restored. Default: None .

返回

Tensor, with the same shape as a.

Supported Platforms:

Ascend GPU CPU

异常
  • TypeError – If input arguments have types not specified above.

  • ValueError – If axis exceeds a.ndim, or shift and axis cannot broadcast.

样例

>>> import mindspore.numpy as np
>>> a = np.reshape(np.arange(12), (3, 4))
>>> print(np.roll(a, [2,-3], [0,-1]))
    [[ 7  4  5  6]
     [11  8  9 10]
     [ 3  0  1  2]]