简体   繁体   English

如何在 scipy 稀疏矩阵中确定索引数组的顺序?

[英]How is the order of the indices array determined in a scipy sparse matrix?

I have two scipy.sparse.csr_matrices with identical non-zero locations.我有两个具有相同非零位置的 scipy.sparse.csr_matrices。 I was assuming that their indptr and indices arrays would be identical.我假设他们的 indptr 和索引数组是相同的。 But it turns out only their indptr arrays are identical (and sorted).但事实证明,只有它们的 indptr 数组是相同的(并已排序)。 The indices array, which stores the columns for any row, are permutations for any row.存储任何行的列的索引数组是任何行的排列。

显示问题的图像

In the image above, let A = sum_predictions and B = Yt_preds[4] be two matrices.在上图中,让 A = sum_predictions 和 B = Yt_preds[4] 是两个矩阵。 Both the matrices have identical non-zero locations.两个矩阵都具有相同的非零位置。 We see that their indptr arrays (number of nonzeros in each row) are identical.我们看到它们的 indptr 数组(每行中的非零数)是相同的。 However the indices arrays (columns for any particular row) are permutations of each other.然而,索引数组(任何特定行的列)是彼此的排列。

How is the order of the indices array in scipy sparse matrix determined?如何确定 scipy 稀疏矩阵中索引数组的顺序? How can I get a representation where two matrices with identical non-zero locations have the same indptr and indices arrays?如何获得具有相同非零位置的两个矩阵具有相同 indptr 和索引数组的表示?

解决方案是mat.sortindices()提出的: mat.sortindices()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM