I have a .txt file from epinion data set which is a sparse representation (ie.
23 387 5 represents the fact "user 23 has rated item 387 as 5") . from this sparse format I want to transfer it to its dense Representation scipy so I can do matrix factorization on it.
I have loaded the file with loadtxt() from numpy and it is a [664824, 3] array. Using scipy.sparse.csr_matrix I transfer it to numpy array and using todense() from scipy I was hoping to achieve the dense format but I always get the same matrix: [664824, 3]. How can I turn it into the original [40163,139738] dense representation?
import numpy as np
from io import StringIO
d = np.loadtxt("MFCode/Epinions_dataset.txt")
S = csr_matrix(d)
D = R.todense()
I expected a dense matrix with the shape of [40163,139738]
sparsedocumentation forcooorcsrformats?csr_matrix(M)makes a sparse matrix fromM, assumingMis itself a 2d dense array. Thecsr_matrix((data, (row, col)))version could use columns from yourdmatrix. Review the examples in the sparse docs. - hpauljmachine-learning- kindly do not spam irrelevant tags (removed). - desertnaut