python - Is there a nice way to check if numpy array elements are within a range? -
this question has answer here:
i want write:
assert np.all(0 < < 2)
where a
numpy
array, doesn't work. what's nice way write this?
you use numpy.logical_and
:
>>> = np.repeat(1, 10) >>> np.logical_and(a > 0, < 2).all() true
or using &
.
>>> ((0 < a) & (a < 2)).all() true
Comments
Post a Comment