Hello i’m a beginner of pytorch,today i appeared a problem while learning the tutorial.I tested the code on jupyter notebook,but it break the error like this:
However,if i changed the type of the variable ‘a’,it works.
Obviously it’s the problem about the dtype of the variable ‘a’,but i really don’t know how to fix this.The version of torch is 1.6(cpu++).
Thanks for reading and replying my problem.
I’m a bit confused as it seems you’ve already fixed it by changing the type of one variable?
not yet,i mean that the variable ‘a’(exactly is a tensor) generate by the function ‘arange’, cannot work on the function ‘scatter’(or ‘scatter_’)
The issue is that the output of
torch.arange has dtype
torch.zeros give output of dtype
torch.float32 thus the scatter works.
Gratefully thanks!After your hint,it really proves that the function scatter,needs every parameter as the same dtype.So just let the variable ‘a’ turns to the dtype torch.float32,exactly just add .float() at the end,and the code works.