欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

相关标签: python python错误