mindspore.ops.rot90

查看源文件
mindspore.ops.rot90(input, k, dims)[源代码]

沿轴指定的平面内将n-D tensor旋转90度。 如果k>0,旋转方向是从第一轴朝向第二轴,如果k<0,旋转方向从第二轴朝向第一轴。

参数:
  • input (Tensor) - 输入tensor。

  • k (int) - 旋转的次数。

  • dims (Union[list(int), tuple(int)]) - 要旋转的轴。

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> 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.]]]