TypeError: sum() received an invalid combination of arguments - got (axis=int, ), but expected one
程序员文章站
2022-05-27 11:59:04
...
错误描述:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-62-d558297b41f8> in <module>
----> 1 A_sum_axis0 = A.sum(axis=0)
2 A_sum_axis0, A_sum_axis0.shape
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, to
import torch
A = torch.arange(20, dtype=torch.float32).reshape(5, 4)
B = A.clone() # 通过分配新内存,将A的一个副本分配给B
A, A + B
A_sum_axis0 = A.sum(axis=0)
A_sum_axis0, A_sum_axis0.shape
解决方法:
修改把axis替换成dim
推荐阅读
-
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: 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, )