assign labels to an existing SparseMatrix

9 views
Skip to first unread message

lexing xie

unread,
Apr 6, 2012, 5:33:55 AM4/6/12
to conceptn...@googlegroups.com
Dear List,
I'm analyzing some data and would like to change the labels to an existing SparseMatrix.  e.g. in the example below. Is there a way I can make the column labels be ["*ruby*", "organge", "*emerald*"] without converting mat1 to list and back?

Is there a method in sparse.py I did not see, or a place to start wrapping existing ones from either divisi or pysparse?
Let me know if this is not enough info.  Many thanks!

>>> from csc import divisi2
>>> mat1 = divisi2.make_sparse([
...     (2, "apple", "red"),
...     (2, "orange", "orange"),
...     (1, "apple", "green"),
...     (1, "celery", "green"),
... ])
>>> print mat1
SparseMatrix (3 by 3)
         red        orange     green
apple    2.000000      ---     1.000000
orange      ---     2.000000      ---
celery      ---        ---     1.000000

Lexing

Kenneth Arnold

unread,
Apr 9, 2012, 12:50:27 PM4/9/12
to conceptn...@googlegroups.com
Sure: mat1.row_labels[0] = 'ruby'

or even mat1.row_labels = OrderedSet(["*ruby*", "organge", "*emerald*"]).

Also, the csc namespace package has been deprecated; the example should read just 'import divisi2'. I was pretty sure we changed all of those, so perhaps the docs somehow got built from an old version.

-Ken


--
You received this message because you are subscribed to the Google Groups "conceptnet-users" group.
To post to this group, send email to conceptn...@googlegroups.com.
To unsubscribe from this group, send email to conceptnet-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/conceptnet-users?hl=en.

Reply all
Reply to author
Forward
0 new messages