Pytorch中报错Expected object of scalar type Long but got scalar type Float

import torch

x1 = torch.arange(6).view(2,3)

x2 = torch.ones(3,2)

x2[:1]+=1

torch.mm(x1, x2)

---------------------------------------------------------------------------

RuntimeError                              Traceback (most recent call last)

<ipython-input-55-25db65725f06> in <module>

----> 1 describe(torch.mm(x1, x2))

RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #3 'mat2' in call to _th_addmm_out

问题的原因是:

x1的tensor类型是Long, x2的tensor类型是Float

把x1 = torch.arange(6).view(2,3)改成x1 = torch.arange(6.0).view(2,3)即可

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容