Iteration over a 0-d tensor

Hi, I use pytorch 1.4.0 but I have a problem:

 raise TypeError('iteration over a 0-d tensor')
 TypeError: iteration over a 0-d tensor

How can I solve this?

You cannot iterate a 0-dim tensor, which is a single scalar.
Either unsqueeze the tensor to create a single dimension or use the value directly.

1 Like

Thank you for your reply but I did it on colab and it’s error is:
PyTorch 0.4.1 is not supported (needs to be 0.3.1)

I’m a bit confused, as your first post mentioned you are using 1.4.0, while now you are downgrading PyTorch to 0.4.1 (or 0.3.1)?

Try to stick with 1.4.0 and either unsqueeze the tensor or don’t try to iterate a scalar value.

In case of loss function, if you try to return more values than the loss function is returning then this error erupts.