相关疑难解决方法(0)

python(scipy):调整稀疏矩阵的大小

我在调整矩阵大小时遇到​​了麻烦 - set_shape函数似乎没有效果:

>>> M
<14x3562 sparse matrix of type '<type 'numpy.float32'>'
   with 6136 stored elements in LInked List format>
>>> new_shape = (15,3562)
>>> M.set_shape(new_shape)
>>> M
<14x3562 sparse matrix of type '<type 'numpy.float32'>'
   with 6136 stored elements in LInked List format>
Run Code Online (Sandbox Code Playgroud)

有人遇到过这个吗?

我也尝试过这样做,即

>>> M._shape = new_shape
>>> M.data = np.concatenate(M.data, np.empty((0,0), dtype=np.float32))
Run Code Online (Sandbox Code Playgroud)

但是这引发了一个错误:

*** TypeError: only length-1 arrays can be converted to Python scalars
Run Code Online (Sandbox Code Playgroud)

要么

>>> M.data = np.concatenate(M.data, [])
*** TypeError: an integer is required …
Run Code Online (Sandbox Code Playgroud)

python scipy sparse-matrix

2
推荐指数
1
解决办法
2829
查看次数

标签 统计

python ×1

scipy ×1

sparse-matrix ×1