I don't know if it's possible, and it's possibly a naive question, but how can I set the equivalent of R's rownames()
and colnames()
to a scipy.sparse.csr.csr_matrix
?
I saw that my_matrix.dtype.names
doesn't work here, and I can't find any "index" equivalend for such sparse matrix...
Moreover, pandas.sparse.*
is not an option here, because of some open issue...
Thank you so much for your help,
You'll have to maintain the names separately, as none of scipy's sparse formats support named indexing. This might look like:
foo = csr_matrix(...)
row_names = np.array(...)
col_names = np.array(...)
# index by name:
row_idx, = np.where(row_names == "my row")
col_idx, = np.where(col_names == "my col")
foo[row_idx, col_idx]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With