rot90

paddle. rot90 ( x, k=1, axes=[0, 1], name=None ) [source]

Rotate a n-D tensor by 90 degrees. The rotation direction and times are specified by axes and the absolute value of k. Rotation direction is from axes[0] towards axes[1] if k > 0, and from axes[1] towards axes[0] for k < 0.

Parameters
  • x (Tensor) – The input Tensor(or LoDTensor). The data type of the input Tensor x should be float16, float32, float64, int32, int64, bool. float16 is only supported on gpu.

  • k (int, optional) – Direction and number of times to rotate, default value: 1.

  • axes (list|tuple, optional) – Axes to rotate, dimension must be 2. default value: [0, 1].

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name .

Returns

Tensor, Tensor or LoDTensor calculated by rot90 layer. The data type is same with input x.

Examples

import paddle

data = paddle.arange(4)
data = paddle.reshape(data, (2, 2))
print(data)
#[[0, 1],
# [2, 3]]

y = paddle.rot90(data, 1, [0, 1])
print(y)
#[[1, 3],
# [0, 2]]

y= paddle.rot90(data, -1, [0, 1])
print(y)
#[[2, 0],
# [3, 1]]

data2 = paddle.arange(8)
data2 = paddle.reshape(data2, (2,2,2))
print(data2)
#[[[0, 1],
#  [2, 3]],
# [[4, 5],
#  [6, 7]]]

y = paddle.rot90(data2, 1, [1, 2])
print(y)
#[[[1, 3],
#  [0, 2]],
# [[5, 7],
#  [4, 6]]]