I would like to find the index of the nearest value according to a thresold value( if there is one)into multidimensional numpy array.
This is part of a bigger project, so I made a more understable exanple. When 31 is calculated, I want to find if already was calculated a number near to 31 calculated. The thresold value could be 10% of 30. For instance,'30' . Then I want replace the index 3000 by -2 into stack array. I made a shorte example but there thousands of numbers I just want to reduce the number of values into my stack array
stack = np.full((7,3), np.nan)
prophomo = np.full((7,5,2), np.nan)
stack[:,2] = np.array([-1,-2,3000,-2,2171,-1,-2])
values1 = np.full((5,2), 20)
values2 = np.full((5,2), 30)
k = 0
for i in range(optstack.shape[0]):
elem = stack[i,2]
if elem == -1:
prophomo[i,:,:] = values1
elif elem == -2:
prophomo[i,:,:] = values2
else:
if k == 0:
prophomo[i,0:-1,0:-1] = 31
else:
prophomo[i,0:-1,0:-1] = 50
k = k + 1