I'm new to Python and could you help me about some basic sparse matrix operation:
How to extract a dense row vector from a sparse matrix without make the whole matrix dense beforehand?
coo_matrix.getrow()
only returns a sparse representation
How to extract a proportion of rows (say, 80%) randomly from a sparse matrix? I need to use them as training data and the proportion left as test data.
Thanks in advance!
coo_matrix.getrow().todense()
csr_matrix
. For sparse matrix A, A[i] will give the ith row. For example:
In [9]: from random import sample
In [10]: A = csr_matrix(...)
In [11]: n = A.shape[0]
In [12]: indices = sample(range(n), 4*n/5)
In [13]: A[indices].todense()