Mauro
unread,Jun 19, 2015, 3:23:19 AM6/19/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to julia...@googlegroups.com
I think the nzrange function (new to 0.4 function) is best to do
that:
Base.nzrange(A, col)
Return the range of indices to the structural nonzero values of a
sparse matrix column. In conjunction with "nonzeros(A)" and
"rowvals(A)", this allows for convenient iterating over a sparse
matrix
A = sparse(I,J,V)
rows = rowvals(A)
vals = nonzeros(A)
m, n = size(A)
for i = 1:n
for j in nzrange(A, i)
row = rows[j]
val = vals[j]
# perform sparse wizardry...
end
end
If you're on 0.3 just add these two definitions from 0.4:
rowvals(S::SparseMatrixCSC) = S.rowval
nzrange(S::SparseMatrixCSC, col::Integer) = S.colptr[col]:(S.colptr[col+1]-1)
(this is just what Odd suggested)
And yes, transposing is likely the fastest for doing this over rows as
indexing into columns is very expensive.