On Thu, Oct 10, 2013 at 1:15 PM, Jérôme Tremblay
<jerome.tremb...@gmail.com> wrote:
> How do I efficiently iterate through a sparse matrix?
>
> SciPy has matrix.tocoo(), what's the equivalent in Sage?

I don't ever remember implementing an iterator over the elements of a
sparse matrix. At least you could make the corresponding dict (of only
nonzero entries) and then iterate over that:

a = matrix(QQ,1000,sparse=True); a[0,5] = 10; a[10,15] = 2/3

for x, y in a.dict().iteritems():
    print x, y

 -- William

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to