如何为 Scipy 稀疏巨大矩阵中的切片赋值
How to assign values to slices in Scipy sparse huge matrix
- 我有一个名为 Mat_A 的巨大矩阵,当我尝试对其进行切片并赋值时,出现以下错误:
Mat_A[:,0 ] = np.ravel(Mat_A.sum(axis=0)) TypeError: coo_matrix' object does not support item assignment
- 如何在稀疏 space 之前以同样的精神为密集矩阵赋值
weights
?
Mat_A = sparse.coo_matrix((weights, (i_indices_O, j_indices_O)), shape=(pixel_nb_O, pixel_nb_O))
Mat_A[:,0 ] = np.ravel(Mat_A.sum(axis=0))
Mat_A[:,1:] = 0
Mat_A = Mat_A.tocsr()
coo_matrix
的稀疏格式有一些缺点,docs:
中提到了这些缺点
does not directly support:
- arithmetic operations
- slicing
COO
是构建稀疏矩阵的快速格式,但对于算术运算,您应该切换到 CSR
或 CSC
.
- 我有一个名为 Mat_A 的巨大矩阵,当我尝试对其进行切片并赋值时,出现以下错误:
Mat_A[:,0 ] = np.ravel(Mat_A.sum(axis=0)) TypeError: coo_matrix' object does not support item assignment
- 如何在稀疏 space 之前以同样的精神为密集矩阵赋值
weights
?
Mat_A = sparse.coo_matrix((weights, (i_indices_O, j_indices_O)), shape=(pixel_nb_O, pixel_nb_O))
Mat_A[:,0 ] = np.ravel(Mat_A.sum(axis=0))
Mat_A[:,1:] = 0
Mat_A = Mat_A.tocsr()
coo_matrix
的稀疏格式有一些缺点,docs:
does not directly support:
- arithmetic operations
- slicing
COO
是构建稀疏矩阵的快速格式,但对于算术运算,您应该切换到 CSR
或 CSC
.