I have an array matrrix Nx4 and I want to reduce it by keeping only the values that are in a specefic range for the second and third column. I have written a code that does not work because it does not take count that I am already reducing the array.
Example of data/array :
1 358 33 7.1
2 659 85 7.1
3 111 145 7.1
4 558 116 7.1
5 632 40 7.1
6 415 335 7.1
7 207 30 7.1
8 564 47 7.1
9 352 41 7.1
10 700 570 7.1
11 275 499 7.1
12 482 177 7.1
13 737 565 7.1
14 298 43 7.1
15 155 195 7.1
16 598 417 7.1
17 93 313 7.1
18 1150 597 7.1
19 410 451 7.1
20 34 793 7.1
21 997 904 7.1
22 1024 452 7.1
23 740 128 7.1
24 522 86 7.1
25 679 643 7.1
26 973 37 7.1
27 372 42 7.1
By example I want to keep the values that are in the range = [80, 2000] for the second column and in the range = [130, 2000] for the third one. My real array has over 1'000'000 rows.
Here is my code :
def filter_data(data, XRANGE, YRANGE) :
data_f = np.copy(data)
for l in range(len(data_f)) :
if XRANGE[0] < data_f[l,1] < XRANGE[1] and YRANGE[0] < data_f[l,1] < YRANGE[1] :
pass
else :
data = np.delete(data, l, axis=0)
return data
How could I do differently and well more efficiently ?