--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-6-68998da09081> in <module> 25 26 # 计算评估指标 ---> 27 true_positive = np.sum(target_labels & x) <__array_function__ internals> in sum(*args, **kwargs) D:\anaconda\envs\pytorch3.6\lib\site-packages\numpy\core\fromnumeric.py in sum(a, axis, dtype, out, keepdims, initial, where) 2240 2241 return _wrapreduction(a, np.add, 'sum', axis, dtype, out, keepdims=keepdims, -> 2242 initial=initial, where=where) 2243 2244 D:\anaconda\envs\pytorch3.6\lib\site-packages\numpy\core\fromnumeric.py in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs) 83 return reduction(axis=axis, dtype=dtype, out=out, **passkwargs) 84 else: ---> 85 return reduction(axis=axis, out=out, **passkwargs) 86 87 return ufunc.reduce(obj, axis, dtype, out, **passkwargs) TypeError: sum() received an invalid combination of arguments - got (axis=NoneType, out=NoneType, ), but expected one of: * (*, torch.dtype dtype) didn't match because some of the keywords were incorrect: axis, out * (tuple of names dim, bool keepdim, *, torch.dtype dtype) * (tuple of ints dim, bool keepdim, *, torch.dtype dtype)
时间: 2024-04-12 10:30:11 浏览: 142
Allow CORS Access-Control-Allow-0.1.9.zip
这个错误是因为在计算 `true_positive` 时使用了 `np.sum()` 函数,但是函数的参数传递错误。`np.sum()` 函数不接受 `axis` 和 `out` 参数为 `NoneType`。要解决这个问题,你可以将 `target_labels` 和 `x` 转换为 numpy 数组,然后使用逻辑与运算符 `&` 计算它们的交集。例如,你可以尝试以下代码:
```python
import numpy as np
# 将 target_labels 和 x 转换为 numpy 数组
target_labels = np.array(target_labels)
x = np.array(x)
# 计算 true_positive
true_positive = np.sum(target_labels & x)
```
阅读全文