Reputation: 715
I get a PEP8 complaint about numpy.where(mask == False)
where mask is a boolean array. The PEP8 recommendation comparison should be either 'if condition is false' or 'if not condition'. What is the pythonic syntax for the suggested comparison inside numpy.where()
?
Upvotes: 0
Views: 951
Reputation: 280207
Negating a boolean mask array in NumPy is ~mask
.
Also, consider whether you actually need where
at all. Seemingly the most common use is some_array[np.where(some_mask)]
, but that's just an unnecessarily wordy and inefficient way to write some_array[some_mask]
.
Upvotes: 1