mindspore.ops.rot90

View Source On Gitee
mindspore.ops.rot90(input, k, dims)[source]

Rotate a n-D tensor by 90 degrees in the plane specified by dims axis. Rotation direction is from the first towards the second axis if k > 0, and from the second towards the first for k < 0.

Parameters
  • input (Tensor) – The input tensor.

  • k (int) – Number of times to rotate.

  • dims (Union[list(int), tuple(int)]) – Axis to rotate.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> x = mindspore.tensor([[1, 2, 3],
...                       [4, 5, 6]], mindspore.float32)
>>> output = mindspore.ops.rot90(x, k=1, dims=(0, 1))
>>> print(output)
[[3. 6.]
 [2. 5.]
 [1. 4.]]
>>> mindspore.ops.rot90(x, k=1, dims=(1, 0)) == mindspore.ops.rot90(x, k=-1, dims=(0,1))
Tensor(shape=[3, 2], dtype=Bool, value=
[[ True,  True],
 [ True,  True],
 [ True,  True]])
>>> # when input array has ndim>2
>>> x = mindspore.tensor([[[1, 2, 3],
...                       [4, 5, 6]],
...                      [[7, 8, 9],
...                       [10, 11, 12]]], mindspore.float32)
>>> output = mindspore.ops.rot90(x, k=1, dims=(2, 1))
>>> print(output)
[[[ 4.  1.]
 [ 5.  2.]
 [ 6.  3.]]
[[10.  7.]
 [11.  8.]
 [12.  9.]]]