Issue
I want to write:
assert np.all(0 < a < 2)
where a
is a numpy
array, but it doesn't work. What's a nice way to write this?
Solution
You could use numpy.logical_and
:
>>> a = np.repeat(1, 10)
>>> np.logical_and(a > 0, a < 2).all()
True
or using &
.
>>> ((0 < a) & (a < 2)).all()
True
Answered By - Ashwini Chaudhary
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.