Reputation: 125
I have a dataset of arrays. I want to take out those array whose values is lying in (0.5, 0.6).
I did it earlier for just less than 0.4
The code is
c_subset = np.array(c)[np.where(np.array(c)<0.4)]
Can anyone help to how to modify the above line to the interval condition?
Upvotes: 1
Views: 52
Reputation: 13415
Use the numpy logical and:
>>> c = [0.50, 0.52, 0.54, 0.56, 0.58, 0.60]
>>> a = np.array(c)
>>> a[(0.5 < a) & (a < 0.6)]
array([0.52, 0.54, 0.56, 0.58])
Note that numpy.where is not necessary.
Upvotes: 3
Reputation: 8982
If your original data doesn't use numpy
and a simple list is sufficient on output, you can do this:
c_subset = [x for x in c if 0.5 < x < 0.6]
Upvotes: 2