RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #2 'mat2'
程序员文章站
2022-03-20 23:29:27
...
在
#线性回归矢量计算
def linreg(X,w,b):
return torch.mm(X,w)+b
报出
RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #2 'mat2'
错误。其主要原因是第二个参数本应该是double类型,但传过来的是float类型。只需要更改一下类型就行。
w = w.double()
上一篇: linux下使用matplotlib绘图报出no display name and no $DISPLAY environment variable错误
下一篇: Python 入门基础学习之路
推荐阅读
-
pytorch RuntimeError: expected scalar type Double but found Float
-
报错:Expected object of scalar type Float but got scalar type Long for argument #2 'target'
-
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got CUDAType
-
RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target'
-
RuntimeError: Expected tensor for argument #1 ‘indices‘ to have scalar type Long; but got CUDAFloatT
-
RuntimeError: Expected tensor for argument #1 ‘indices‘ to have scalar type Long; but got torch.IntT
-
Expected object of scalar type Long but got scalar type Int for argument #2 'target'
-
RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 'target'
-
Expected object of scalar type Long but got scalar type Double for argument #2 'target'
-
Expected object of scalar type Float but got scalar type Long for argument #2 'target'