[SciPy-User] [SciPy-user] sparse matrices - scipy

villamil villamil at brandeis.edu
Wed Jun 8 10:29:26 EDT 2011


That's exactly what I needed, and it wasn't very hard too. 
Thank you. 


Andrew MacLean-3 wrote:
> 
> If you are just trying to find the number of non-zero values in a
> particular row, a command like S[i,:].size or for a column S[:,j].size
> should work. Here, S could be of type csc, csr, lil or probably also
> dok as these all support indexing and slicing.  csc is best for column
> slicing, and csr is best for row slicing, so you could also use
> different types. csc and csr types do not support assignment though,
> while lil and dok do.
> 
> For adding all the entries in each column, I think the csc type would
> be best. A code like S[:,j].sum() should work (see
> http://docs.scipy.org/doc/scipy-0.9.0/reference/generated/scipy.sparse.csc_matrix.sum.html#scipy.sparse.csc_matrix.sum).
> 
> 
> On Jun 7, 3:20 pm, villamil <villa... at brandeis.edu> wrote:
>> I just recently started using python a couple of weeks ago, and I have an
>> application with sparse matrices, so I found I need the Scipy package for
>> this.
>> So I have a sparse matrix S, and I want to do operations on its rows and
>> columns:
>> -find the count of the nonzero entries in each row  S[i,:]
>> -add all the entries in each column  S[:,j]
>>
>> Is there a way to do this, or do I need to access all the elements?,  
>> Is there one particular format csc, csr, lil, coo, dok for which this is
>> easier?
>>
>> Thank you
>> --
>> View this message in
>> context:http://old.nabble.com/sparse-matrices---scipy-tp31792885p31792885.html
>> Sent from the Scipy-User mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-U... at scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
> 
> 

-- 
View this message in context: http://old.nabble.com/sparse-matrices---scipy-tp31792885p31801164.html
Sent from the Scipy-User mailing list archive at Nabble.com.




More information about the SciPy-User mailing list