Re: How to read row_name, col_name, value format TSV into a sparse matrix?

Thomas Kluyver <[email protected]> Wed, 29 Jan 2020 09:19:12 +0000
Newsgroups gmane.comp.python.scientific.user
Message-ID <CAOvn4qg51-8-myaD53Ptaw5CN5KiYNpVhEE_+f6WUcPfyCS=BA@mail.gmail.com>
Reading the csv/tsv (either with pandas or numpy) doesn't create a matrix
at all. It just gives you the data as it is in the file: values with
associated coordinates. Then you would use something like
scipy.sparse.coo_matrix() to convert that to a sparse matrix.

On Wed, 29 Jan 2020 at 08:47, Peng Yu <[email protected]> wrote:

> 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
> _______________________________________________
> SciPy-User mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/scipy-user
>

_______________________________________________
SciPy-User mailing list
[email protected]
https://mail.python.org/mailman/listinfo/scipy-user