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

Lingyi Hu lingyihuu at gmail.com
Wed Jan 29 04:44:27 EST 2020


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 <pengyu.ut at gmail.com> 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
> SciPy-User at python.org
> https://mail.python.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20200129/f042ec19/attachment.html>


More information about the SciPy-User mailing list