There are various questions regarding filtering of the numpy arrays including:
But I have a slightly different issue:
>>> x = np.empty(shape=(5,), dtype=[('ts', 'i8'), ('data', 'i8')])
>>> x['ts'] = [0, 1, 2, 5, 6]
>>> x['data'] = [1, 2, 3, 4, 5]
>>> x
array([(0, 1), (1, 2), (2, 3), (5, 4), (6, 5)],
dtype=[('ts', '<i8'), ('data', '<i8')])
>>> x[(x['ts'] > 2) & (x['ts'] < 4.9)]
array([], dtype=[('ts', '<i8'), ('data', '<i8')])
>>>
This is exactly what I would expect. However, I need the filtered array to include 5 as well. Is there a way to filter it other then with a for or a while loop iterating over rows of the array and including the row with index following the last row matching the condition?
5as well"?tswhere the end condition is < 5 but I need to have the row wherets== 5 also included.<= 5?x[(x['ts'] > 2) & (x['ts'] <= 5)]ts. When I have to filter I don't know that the 5 is the nextts. All I know is the minimum and maximum