How do I copy, for example, the 1 index of the first dimension of a 3d tensor, and create a new tensor with only that information?
For example in a tensor of [5,25,25], how do I copy [x,25,25] and create a new tensor [1,25,25]?
How do I copy, for example, the 1 index of the first dimension of a 3d tensor, and create a new tensor with only that information?
For example in a tensor of [5,25,25], how do I copy [x,25,25] and create a new tensor [1,25,25]?
Sorry, is this what you are asking (the size 25 is changed to 3 to illustrate)…
>>> a = torch.randn(3, 3, 3)
>>> a
tensor([[[ 0.0637, -0.7271, 0.9669],
[-1.5508, -0.5795, 0.7472],
[-0.9258, 0.6464, 0.7641]],
[[-0.4879, 0.8104, 1.3433],
[-0.3241, -1.3570, -0.2355],
[ 2.1369, 0.1334, 1.2353]],
[[-0.6005, 1.5156, -0.4654],
[ 0.3012, 0.7669, -0.1073],
[-0.2972, 0.2404, -1.3757]]])
>>> x = 1
>>> b = a[x, :, :].clone()
>>> b
tensor([[-0.4879, 0.8104, 1.3433],
[-0.3241, -1.3570, -0.2355],
[ 2.1369, 0.1334, 1.2353]])
Yes! Thank you, that is really helpful!