import time
import torch
from torch import nn,optim
import numpy as np
import torch.nn.functional as F
from torch.optim import lr_scheduler
import torchvision.transforms
w=[]
for i in range(14):
    w1=[]
    for j in range(14):
        w1.append(i)
    w1=np.array(w1)
    w.append(w1)
w=np.array(w)
w=np.reshape(w,(1,14,14))
w=torch.Tensor(w)
print(w.shape)
e=torchvision.transforms.RandomRotation((9,10))
print(e.forward(w))
输出:

tensor([[[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 1., 1., 1., 0.],
[ 0., 0., 0., 0., 1., 1., 1., 1., 1., 1., 2., 2., 2., 0.],
[ 1., 1., 1., 1., 2., 2., 2., 2., 2., 2., 3., 3., 3., 0.],
[ 2., 2., 2., 2., 3., 3., 3., 3., 3., 3., 4., 4., 4., 4.],
[ 3., 3., 3., 3., 4., 4., 4., 4., 4., 4., 5., 5., 5., 5.],
[ 4., 4., 4., 4., 5., 5., 5., 5., 5., 5., 6., 6., 6., 6.],
[ 5., 5., 5., 5., 6., 6., 6., 6., 6., 6., 7., 7., 7., 7.],
[ 6., 6., 6., 6., 7., 7., 7., 7., 7., 7., 8., 8., 8., 8.],
[ 7., 7., 7., 7., 8., 8., 8., 8., 8., 8., 9., 9., 9., 9.],
[ 8., 8., 8., 8., 9., 9., 9., 9., 9., 9., 10., 10., 10., 10.],
[ 9., 9., 9., 9., 10., 10., 10., 10., 10., 10., 11., 11., 11., 11.],
[ 0., 10., 10., 10., 11., 11., 11., 11., 11., 11., 12., 12., 12., 12.],
[ 0., 11., 11., 11., 12., 12., 12., 12., 12., 12., 13., 13., 13., 13.],
[ 0., 12., 12., 12., 12., 13., 13., 13., 13., 13., 13., 0., 0., 0.]]])

将二维向量进行旋转,角度为正是向左旋转,故出现左边的1向下沉,右边的1向上升。

缺少的部分补0。