[SciPy-User] [SciPy-user] sparse matrices - scipy
Andrew MacLean
andrew.maclean at gmail.com
Tue Jun 7 23:30:26 EDT 2011
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
More information about the SciPy-User
mailing list