I have a large sparse array (Python csr). How can I find the indices of columns that are not entirely zeros?
For example, if the matrix looks like s constructed below
In [13]: import scipy.sparse as sparse
In [14]: s=sparse.dok_matrix((2,4))
In [15]: s[0,0]=8; s[0,3]=9
In [16]: print (s.toarray())
[[8. 0. 0. 9.]
[0. 0. 0. 0.]]
The nonzero indices for the matrix s will be [0,3].
>Solution :
I think you can use:
import numpy as np
np.nonzero((s!=0).sum(0))[1]
output: [0, 3]