I have the following code:
zero_indices = np.where(A==0)
nonzero_indices = np.where(A!=0)
But I want to find zero_indices and nonzero_indices with just a single call of np.where.
One way I found to do this is:
zero_indices = np.where(array == 0)
non_zero_indices = np.setdiff1d(np.arange(array.size), zero_indices)
However, when testing on large arrays, I found that this is actually 10x slower than just calling np.where twice.
Is there a more efficient way to do this?
New contributor
C.M.O.B. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.