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

Lingyi Hu <[email protected]> Wed, 29 Jan 2020 17:44:27 +0800
Newsgroups gmane.comp.python.scientific.user
Message-ID <CAApfPRzn28mNAMM=xKGJMj4vb2Fup0xutHrAXdnc73ho6BybWg@mail.gmail.com>
Hi Peng Yu,

Seems like these links might be useful:

https://stackoverflow.com/questions/1938894/csv-to-sparse-matrix-in-python
https://gist.github.com/oddskool/27476a1e22df357de798

Should be easy to switch out csv for tsv parsing.

Lingyi

On Wed, Jan 29, 2020 at 5:34 PM Peng Yu <[email protected]> wrote:

> > 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.
>
> Where it documented that pandas.read_csv don't generate the whole
> matrix? The return value is either of the two?
>
> """
> DataFrame or TextParser
>
>     A comma-separated values (csv) file is returned as two-dimensional
> data structure with labeled axes.
> """
>
> Are you referring "TextParser"? How to control which one to return? I
> don't see an option for it.
>
> Which function of numpy do refer to specifically? numpy.loadtxt? It
> returns ndarray, which should read a dense matrix into the memory.
>
> --
> 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