TypeError: sum() received an invalid combination of arguments - got (axis=int, ), but expected one

错误描述:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
 in 
----> 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,程序报错)