permute针对的是转换维度,view等价于reshape。
permute作用为调换Tensor的维度,参数为调换的维度。例如对于一个二维Tensor来说,调用tensor.permute(1,0)意为将1轴(列轴)与0轴(行轴)调换,相当于进行转置。
In [20]: a
Out[20]:
tensor([[0, 1, 2],
[3, 4, 5]])
In [21]: a.permute(1,0)
Out[21]:
tensor([[0, 3],
[1, 4],
[2, 5]])
view
x = torch.randn(4, 4)
x.size()
torch.Size([4, 4])y = x.view(16)
y.size()
torch.Size([16])



