Skip to content

Boolean Slicing Across an Array #685

Answered by Scico5
Scico5 asked this question in Q&A
Discussion options

You must be logged in to vote

I believe I have an answer based on a bug report from this repo.

You can do this using np.where:

import ulab.numpy as np
a=np.array([[1,2,3],[2,3,4],[5,6,7]])
b=a[:,1]==3
c=b.reshape((len(b),1))
d=np.where(c,a,np.nan)

Then in the d array you have converted all invalid rows to nan's, Now you can repeat the process on d using the next boolean operation on the other column of interest and you're left with only valid data.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by v923z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant