We can use the tensor.size() to get the rank of a tensor, below is the code to get the same:
size_tensor = list(my_tensor.size())
Complete code:
import torch
my_data = [[0.8741, 0.0762, 0.7213, 0.1766, 0.6062, 0.3769],
[0.3332, 0.9581, 0.7579, 0.4698, 0.6268, 0.1420]]
my_tensor = torch.Tensor(my_data)
size_tensor = list(my_tensor.size())
print("Size of tensor:", size_tensor)
Output:
Size of tensor: [2, 6]
Above, the tensor in the example is of size 2, 6.