[SciPy-User] How to read row_name, col_name, value format TSV into a sparse matrix?

Peng Yu pengyu.ut at gmail.com
Wed Jan 29 03:46:34 EST 2020


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


More information about the SciPy-User mailing list