user3692741
user3692741

Reputation:

How to get boolean or of two numpy masks with Python

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

Upvotes: 1

Views: 2892

Answers (3)

tom10
tom10

Reputation: 69172

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

Upvotes: 1

Roy Shahaf
Roy Shahaf

Reputation: 494

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

Upvotes: 2

user3692741
user3692741

Reputation:

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

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

Upvotes: 1

Related Questions