How can I fetch the rows for which the second column equals to 4 or 6?
a = np.array(np.mat('1 2; 3 4; 5 6; 7 4'))
b = [4,6]
Apparently, this does not work:
c = a[a[:,1] in b]
The numpythonic way of doing this would be to use in1d
, something like:
a[np.in1d(a[:, 1], b)]
You can do:
check = np.logical_or(a[:,1]==4, a[:,1]==6)
c = a[check,:]
You can also use |
for the logical operator or
:
check = (a[:,1]==4) | (a[:,1]==6)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With