I struggled with the task of having an inequality threshold superimposed on kadjacent elements in an array with a 1-dimensional matrix - I have to add both left and right. For instance:
if x[i+-100] < .05:
This is better than I can formulate it, obviously this will not work. But I hope that my point of view is clearer. In other words, I would like to distinguish if any elements within plus or minus 100 elements of element x have a value greater than 0.05. Here is my entire function for context: (here I have -.05)
def vector_recode(x):
if (x[i+-100]) > .05 or (x[i+-100]) < -.05:
return X
else:
return 0
recode_function = np.vectorize(vector_recode)
- For clarity, the above function tries to take values that are close enough to zero and reset them to zero, or if there are any nearby [+ -100] elements that have a value greater than .05 in absolute terms, keep x as it is.
I have a drowning feeling that I might have to resort to a loop, but np always surprised me with its efficiency, and I hope someone has an understanding that could help me, others like me, in dealing with kadjacent items.
My other study of this procedure also includes scipy.ndimageconvolution matrices. However, I do not think that this approach is easily applicable to my case - it's just 1D left and right neighboring elements. I used to be wrong. Any help is appreciated.
If this helps, I will try to make a worked-out example:
>>>A
[0.04,0.03,0.03,0.02,0.04]
>>>recode_function(A)
[0,0,0,0,0]
>>>B
[0.03,0.02,0.23,0.01,0.03]
>>>recode_function(B)
[0.03,0.02,0.23,0.01,0.03]
"" " 100" "" " 5.". "" 0,05 -5,0, . "B" 0,05. 0,23, , x, 5 x. -, . "A" "B" 1 . , - , . , .