How do you check the shape of tensors?

Hi!

I am very curious about your approaches of checking shapes of tensors. I am not sure if this is even a normal thing to do, but I often run into errors due to missmatches of the shapes of tensors. Thus, I often (very beginner like, I know) use print statements to check the size of a tensor and make changes accordingly. Debugging takes way more time for me to get the actual shape, so I am curious what is considered best practice here? How do you check the shape of tensors? Or is this something only beginners do in the first place.

1 Like

Na it’s not just a beginner thing, I inspect tensor shapes all the time

import torch

v = torch.tensor([[ 1 , 0 ],[ 0 , 1 ]])

x = list (v.shape)

print (x)

Granted there are some tools that might help you visualize all the shapes in one go like TensorSensor