访问csr_matrix中的特定行列

时间:2021-10-31 21:45:21

I have a sparse matrix in csr format (which makes sense for my purposes, as it has lots of rows but relatively few columns, ~8million x 90).

我有一个csr格式的稀疏矩阵(这对我的目的来说很有意义,因为它有很多行,但列数相对较少,约为8百万x 90)。

My question is, what's the most efficient way to access a particular value from the matrix given a row,column tuple? I can quickly get a row using matrix.getrow(row), but this also returns 1-row sparse matrix, and accessing the value at a particular column seems clunky. The only reliable method I've found to get a particular matrix value, given the row and column, is:

我的问题是,在给定行,列元组的情况下,从矩阵访问特定值的最有效方法是什么?我可以使用matrix.getrow(row)快速获取一行,但这也会返回1行稀疏矩阵,并且访问特定列的值似乎很笨拙。在给定行和列的情况下,我发现获得特定矩阵值的唯一可靠方法是:

matrix.getrow(row).todense().A1[column]

But this seems overly verbose and complicated. Is there a simpler/faster method I'm missing?

但这似乎过于冗长和复杂。我缺少一个更简单/更快的方法吗?

1 个解决方案

#1


12  

You can get the value as usual from matrix[row,column].

您可以像往常一样从矩阵[row,column]中获取值。

#1


12  

You can get the value as usual from matrix[row,column].

您可以像往常一样从矩阵[row,column]中获取值。