numpy.sum() 给出 `TypeError: sum() got an unexpected keyword argument ' dtype'`

标签 numpy scipy sparse-matrix

以下代码生成了意外 TypeError :

import scipy.sparse
import numpy

coomatrix = scipy.sparse.coo_matrix((100,100))
numpy.sum(coomatrix)

结果:
TypeError: sum() got an unexpected keyword argument 'dtype'
scipy版本 0.14.0,numpy版本 1.9.0

最佳答案

问题是numpy.sum不知道如何处理稀疏矩阵。以下按预期工作:

coomatrix.sum()

关于numpy.sum() 给出 `TypeError: sum() got an unexpected keyword argument ' dtype'`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26309615/

相关文章:

python - 使用numpy计算数组连续点之间的欧氏距离

python - 在 numpy/scipy 中求解最小二乘?

python - 使用 Numpy 将 MATLAB 切片转换为 Python

python - 将 1x1 稀疏矩阵转换为标量

python - 反向排序python中的二维numpy数组

python - 使用 while 循环递增数组中的值,直到所有值 => 100

tensorflow - 获取 SparseTensor 的非零行

matlab - 密集和稀疏向量的总和

python - 替换所有高于阈值的 RGB 值

python - ValueError : matmul: Input operand 1 has a mismatch in its core dimension 0,,带有 gufunc 签名 (n?,k),(k,m?)->(n?,m?)(大小 1 与 3 不同)