import torch as
a=t.rand(4,3,28,28)
a[0].shape
torch.Size([3, 28, 28])
a[0,0].shape
torch.Size([28, 28])
a[0,0,2,4]
tensor(0.0997)
a.shape
torch.Size([4, 3, 28, 28])
a[:2].shape
torch.Size([2, 3, 28, 28])
a[:2,:1,:,:].shape
torch.Size([2, 1, 28, 28])
a[:2,1:].shape
torch.Size([2, 2, 28, 28])
a[:2,-1:].shape
torch.Size([2, 1, 28, 28])
a[:,:,0:28:2,0:28:2].shape
torch.Size([4, 3, 14, 14])
a[:,:,::2,::2].shape
torch.Size([4, 3, 14, 14])
a.shape
torch.Size([4, 3, 28, 28])
a.index_select(0,t.tensor([0,2])).shape
torch.Size([2, 3, 28, 28])
a.index_select(1,t.tensor([1,2])).shape
torch.Size([4, 2, 28, 28])
a.index_select(2,t.arange(28)).shape
torch.Size([4, 3, 28, 28])
a.index_select(2,t.arange(8)).shape
torch.Size([4, 3, 8, 28])
a.shape
torch.Size([4, 3, 28, 28])
a[...].shape
torch.Size([4, 3, 28, 28])
a[0,...].shape
torch.Size([3, 28, 28])
a[:,1,...].shape
torch.Size([4, 28, 28])
a[...,:2].shape
torch.Size([4, 3, 28, 2])
x=t.randn(3,4)
mask=x.ge(0.5)
t.masked_select(x,mask)
tensor([0.6327, 0.9343, 0.8746])
t.masked_select(x,mask).shape
torch.Size([3])