import torch a = torch.LongTensor([[1,2,3],[4,5,6]]) print(a.dim()) #returns 2, i.e the number of dimensions of a tensor print(a.size()) #returns the size of the tensor i.e. 2x3 print(a.size(1)) #returns the size of the second dimension of the tensor i.e. 3
import torch a = torch.LongTensor([[1,2,3],[4,5,6]]) print(torch.sum(a, dim=1)) #sums the elements along the second dimension to give tensor([ 6, 15]) print(torch.mean(a, dim=0)) #takes the mean of the elements along the first dimension to give tensor([2.5000, 3.5000, 4.5000])The package library used in the above examples is the PyTorch library.