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

Guillaume Gay <[email protected]> Wed, 29 Jan 2020 08:29:24 +0100
Newsgroups gmane.comp.python.scientific.user
Message-ID <[email protected]>
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


G.

Le 29/01/2020 à 04:44, Peng Yu a écrit :
> No. Which one to try?
>
> Just to be clear I want to eventually use the sparse matrix with
> sklearn's .fit().
>
> On 1/28/20, Hjalmar Turesson <[email protected]> wrote:
>> Have you tried using Pandas?
>>
>> https://pandas.pydata.org/pandas-docs/stable/user_guide/sparse.html
>>
>> On Tue, Jan 28, 2020 at 10:09 PM Peng Yu <[email protected]> wrote:
>>
>>> Suppose that I have a TSV file in the following format.
>>>
>>> ```
>>> row_name<TAB>col_name<TAB>value
>>> ```
>>>
>>> Is there an easy way to read it into a sparse matrix format in scipy?
>>> Thanks.
>>>
>>> I don't see such examples in the doc.
>>>
>>> https://docs.scipy.org/doc/scipy/reference/sparse.html
>>>
>>> --
>>> Regards,
>>> Peng
>>> _______________________________________________
>>> SciPy-User mailing list
>>> [email protected]
>>> https://mail.python.org/mailman/listinfo/scipy-user
>>>
>
-- 
Guillaume Gay, PhD

Morphogénie Logiciels SAS
http://morphogenie.fr

12 rue Camoin Jeune
13004 Marseille

  +336 51 95 94 00

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