Accessing a specific row, column in the csr_matrix
I have a sparse matrix in csr format (which makes sense for my purposes, since it has many rows but relatively few columns, ~ 8 million x 90).
My question is, what's the most efficient way to access a specific value from a matrix given by a row, tuple of columns? I can quickly get a row using matrix.getrow(row)
, but this also returns a sparse matrix with 1 row and accessing the value in a specific column seems clunky. The only reliable method I've found to get the specific value of a matrix given a row and a column is:
matrix.getrow(row).todense().A1[column]
But this seems too wordy and complicated. Is there an easier / faster method that I am missing?
+3
source to share