cx = x.tocoo()
for i,j,v in itertools.izip(cx.row, cx.col, cx.data):
(i,j,v)
That iterator is incredibly fast, but unfortunately coo_matrix does not support assignment. So I create a new copy of either a dok sparse matrix or a regular numpy array and assign to that. I could also deal directly with the .data, .indptr, and indices attributes of csr_matrix, and see if it's possible to create a copy of .data attribute and update the values accordingly. I was hoping somebody had encountered this type of issue before.Sincerely,Basil Beirouti