How can I know I’m dealing with a number or a tensor other than checking the dim() method?

is there a method for this? or should I just use dim() for this?

Thank you all in advance

i think type(variable) is what you want

1 Like

using type only results in `<class 'torch.Tensor'>`

for everything in this case.

Thanks, I have sth like :

```
if one_hot_tensor.size(0) > 1 :
return torch.argmax(one_hot_tensor)
else:
return one_hot_tensor[0].int()
```

and this always returns a tensor and none of these proposed methods work!

it means that one_hot_tensor.size(0) > 1 has always been true, and torch.argmax() will return a tensor

1 Like