Given a = torch.randn(3, 2, 4, 5)
, how I can select sub tensor like (2, :, 0, :), (1, :, 1, :), (2, :, 2, :), (0, :, 3, :)
(a resulting tensor of size (2, 4, 5)
or (4, 2, 5)
?
While a[2, :, 0, :]
gives
0.5580 -0.0337 1.0048 -0.5044 0.6784
-1.6117 1.0084 1.1886 0.1278 0.3739
[torch.FloatTensor of size 2x5]
however, a[[2, 1, 2, 0], :, [0, 1, 2, 3], :]
gives
TypeError: Performing basic indexing on a tensor and encountered an error indexing dim 0 with an object of type list. The only supported types are integers, slices, numpy scalars, or if indexing with a torch.LongTensor or torch.ByteTensor only a single Tensor may be passed.
though numpy
returns a (4, 2, 5)
tensor successfully.