1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| >> a = torch.randn(2,3,5) >> b = torch.transpose(a,1,2) >> c = a.view(2,5,3) >> print(a) tensor([[[ 0.9926, -0.1669, -1.6571, -0.2730, -0.1313], [ 0.9811, -1.9854, 1.5519, 0.1383, 1.4571], [ 0.8221, -1.1283, -0.7675, -2.0497, 0.4748]],
[[ 0.1594, 0.7166, -0.2603, 1.1027, 1.5283], [-0.7652, -1.4711, 0.5077, 0.6639, 0.0374], [ 1.8121, -1.4864, -2.9863, -0.5769, -0.2915]]]) >> print(b) tensor([[[ 0.9926, 0.9811, 0.8221], [-0.1669, -1.9854, -1.1283], [-1.6571, 1.5519, -0.7675], [-0.2730, 0.1383, -2.0497], [-0.1313, 1.4571, 0.4748]],
[[ 0.1594, -0.7652, 1.8121], [ 0.7166, -1.4711, -1.4864], [-0.2603, 0.5077, -2.9863], [ 1.1027, 0.6639, -0.5769], [ 1.5283, 0.0374, -0.2915]]]) >> print(c) tensor([[[ 0.9926, -0.1669, -1.6571], [-0.2730, -0.1313, 0.9811], [-1.9854, 1.5519, 0.1383], [ 1.4571, 0.8221, -1.1283], [-0.7675, -2.0497, 0.4748]],
[[ 0.1594, 0.7166, -0.2603], [ 1.1027, 1.5283, -0.7652], [-1.4711, 0.5077, 0.6639], [ 0.0374, 1.8121, -1.4864], [-2.9863, -0.5769, -0.2915]]])
|