You can get exactly what you want, with logical operations between matrices. for instance
print((np.r_[1, 2, 3, 4, 5] > 3))
will give
[False False False True True]
And if you want integers, you can do
print((np.r_[1, 2, 3, 4, 5] > 3).astype(int) )
and get
[0 0 0 1 1]
source
share