Hi together,
I have a scipy.sparse.dok_matrix
(dimensions m x n), wanting to add a flat numpy-array with length m.
for col in xrange(n):
dense_array = ...
dok_matrix[:,col] = dense_array
However, this code raises an Exception in dok_matrix.__setitem__
when it tries to delete a non existing key (del self[(i,j)]
).
So, for now I am doing this the unelegant way:
for col in xrange(n):
dense_array = ...
for row in dense_array.nonzero():
dok_matrix[row, col] = dense_array[row]
This feels very ineffecient. So, what is the most efficient way of doing this?
Thanks!