1

Given two numpy array masks, created with the 3rd and 4th columns of data of 7 columns total:

exp_mask = np.repeat(data[:,2]>7., data.shape[1])
loggf_mask = np.repeat(data[:,3]<-7., data.shape[1])

How can I mask data which are masked by either exp_mask or loggf_mask?

The logic of what I am trying to describe is:

mask = exp_mask or loggf_mask
0

3 Answers 3

2

I believe you are looking for a bitwise or, which is |.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use np.any() to evaluate boolean or on masks:

mask = np.any([exp_mask,loggf_mask],axis=0)

Comments

1

You can use either bitwise_or, which also has the | shorthand, or logical_or. Both will work since your array will be of type bool:

mask = exp_mask | loggf_mask

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.