1

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
3
  • stackoverflow.com/questions/2566412/… should get you there. Commented Jan 13, 2015 at 16:38
  • I want to find the nearest vector in multidimensional array. These answers are about nearest value Commented Jan 14, 2015 at 11:02
  • Your example gives single numbers (31, 30). But I think you can get there for vectors with proper slicing in your input. Commented Jan 14, 2015 at 11:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.