Re: How to read row_name, col_name, value format TSV into a sparse matrix?
Peng Yu <[email protected]> Wed, 29 Jan 2020 02:46:34 -0600
| Newsgroups | gmane.comp.python.scientific.user |
|---|---|
| Message-ID | <CABrM6wnZoNKZyAPyxm0wT8uNPqX7oyKVbmkjRp11DwvCdxUwMg@mail.gmail.com> |
But does pandas read_csv generate a dense matrix? (I don't find numpy read_csv. I only find numpy.loadtxt, which also only deal with dense matrix.) What is the purpose of read into a dense matrix then convert it to a sparse one? Isn't it better to directly read into a sparse matrix to save memory? Thanks. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.loadtxt.html > You can either use pandas or numpy.read_csv. If the row_name and > col_name columns contain the indices, you can then instanciate a > scipy.sparse matrix with sparse.coo_matrix(val, (row, col))) > > https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html#scipy-sparse-coo-matrix -- Regards, Peng