numpy矩阵求和 TypeError: sum() received an invalid combination of arguments - got (axis=int, )
程序员文章站
2022-03-03 14:36:42
...
代码:
target.sum(axis=0)
报错:
Traceback (most recent call last):
File "/home/user1/test.py", line 101, in <module>
t = target.sum(axis=0).reshape((1, 40))
TypeError: sum() received an invalid combination of arguments - got (axis=int, ), but expected one of:
* ()
didn't match because some of the keywords were incorrect: axis
* (torch.dtype dtype)
didn't match because some of the keywords were incorrect: axis
* (tuple of ints dim, torch.dtype dtype)
* (tuple of ints dim, bool keepdim, torch.dtype dtype)
* (tuple of ints dim, bool keepdim)
原因:你操作的是一个torch.tensor,需要先转成numpy array才能进一步求和。
解决:
target = target.numpy() # convert torch.tensor to numpy array
感谢:Shai @ https://*.com/questions/54999926/pytorch-typeerror-eq-received-an-invalid-combination-of-arguments
上一篇: pytorch AttributeError: ‘tuple‘ object has no attribute ‘dim‘
下一篇: ubuntu 16.04重装/升级 nvidia显卡驱动,NVIDIA-SMI has failed because it couldnt communicate with the NVIDIA d
推荐阅读
-
TypeError: new() received an invalid combination of arguments-got(float, int)
-
TypeError: new() received an invalid combination of arguments - got (float, int, int, int), but expe
-
TypeError: rsub() received an invalid combination of arguments - got (Tensor, numpy.ndarray), but
-
TypeError: sum() received an invalid combination of arguments - got (axis=int, ), but expected one
-
TypeError: transpose() received an invalid combination of arguments - got (int, int, int, int), but
-
TypeError: new() received an invalid combination of arguments - got (float, int), but expected one
-
numpy矩阵求和 TypeError: sum() received an invalid combination of arguments - got (axis=int, )