'is there a way to compare a value to a moving range in an array?
I am iterating through the main data set and wanting to compare column 22s data to a specific value (j, k, or l depending on which if statement or phase in the analysis). So for example in the first if statement I am searching for the high value in the first part of the dataset. When the value increases I save the new value to "j" and want to compare the new "j" to the next n values in the array which I tried to do with:
val > data[i+1, 22] and val > data[i+2, 22] and val > data[i+3, 22] and val > data[i+4, 22]:
Is there some method to do something like:
if data[i:i+10, 22] < val:
then do what i have in the actions of the if statement?
If thinking about it while I'm writing this maybe just taking a max value of a range would be the best method then maybe expanding that range to see when if the value changes. Then skip to the next step/if statement where I am finding the minimum and do the same iteration and so on? This data set has around 70000 lines and multiple cycles where i am wanting to get these points for each cycle. And also i have multiple files to do this exact same thing with.
j = 0
k = 10
l = 0
ii = 0
r = 10
for i, val in enumerate(data[:,22]):
if val > 0 and k == 10 and val >= j and ii == 0 and val > data[i+1, 22] and val > data[i+2, 22] and val > data[i+3, 22] and val > data[i+4, 22]:
data[i, 23] = 1
j = val
ii = i + 50
if val > 0 and j > 0 and l == 0 and val <= k and i >= ii and val < data[i+1, 22] and val < data[i+2, 22] and val < data[i+3, 22] and val < data[i+4, 22]:
data[i, 23] = 2
k = val
ii = i + 50
if val > 0 and j > 0 and k < 10 and val >= l and data [i, 23] != 1 and i >= ii and val > data[i+1, 22] and val > data[i+2, 22] and val > data[i+3, 22] and val > data[i+4, 22]:
data[i, 23] = 3
l = val
ii = 0
Some sample data is here
Weird, just noticed the data was pasted out of order and not sure why but hopefully you can get the idea.
index value
916 0.7885863333
917 0.7885863333
918 1.1828793333
919 0.7885863333
920 0.394293
888 0.5499353333
889 0.5706876667
890 0.300908
891 0.3009076667
892 0.612192
893 0.6329443333
894 0.6433203333
895 0.6640726667
896 0.6744486667
897 0.684825
898 0.705577
899 0.705577
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

