本系列文章配套代码获取有以下两种途径:
-
通过百度网盘获取:
链接:https://pan.baidu.com/s/1XuxKa9_G00NznvSK0cr5qw?pwd=mnsj
提取码:mnsj
-
前往GitHub获取:
https://github.com/returu/PyTorch
t/T():
>>> a = torch.randn(3,4)
>>> a
tensor([[ 0.9782, -0.8856, -1.4474, -0.6651],
[-0.9384, 0.3654, 0.0169, -0.8105],
[ 0.9884, 0.3084, -0.3560, 1.5181]])
>>> a.t()
tensor([[ 0.9782, -0.9384, 0.9884],
[-0.8856, 0.3654, 0.3084],
[-1.4474, 0.0169, -0.3560],
[-0.6651, -0.8105, 1.5181]])
>>> a.t().shape
torch.Size([4, 3])
transpose():
>>> a = torch.randn(4,3,14,28)
# 交换第1和第3个维度
>>> a.transpose(1,3).shape
torch.Size([4, 28, 14, 3])
permute():
>>> a = torch.randn(4,3,14,28)
# [batch,channel,h,w] → [batch,h,w,channel]
>>> a.permute(0,2,3,1).shape
torch.Size([4, 14, 28, 3])
更多内容可以前往官网查看:
https://pytorch.org/
本篇文章来源于微信公众号: 码农设计师