0

The function below separates each value into chunks separated by indexes index with the values in L_list. So it outputs the minimum value between indexes 3-5 which is -5 and the index of the value. Both the numpy_argmin_reduceat(a, b) and the Drawdown function do as planned however the index output of the numpy_argmin_reduceat(a, b) is faulty it The minimum values of Drawdown do not match with the indexes of the outputs of numpy_argmin_reduceat(a, b).How would I be able to solve this? Arrays:

import numpy as np
# indexes          0, 1, 2,3,4, 5, 6,7, 8, 9,10, 11, 12
L_list = np.array([10,20,30,0,0,-5,11,2,33, 4, 5, 68, 7])
index =  np.array([3,5,7,11])

Functions:

#getting the minimum values
Drawdown = np.minimum.reduceat(L_list,index+1)

#Getting the min Index 
def numpy_argmin_reduceat(a, b):
    n = a.max() + 1  # limit-offset
    id_arr = np.zeros(a.size,dtype=int)
    id_arr[b] = 1
    shift = n*id_arr.cumsum()
    sortidx = (a+shift).argsort()
    grp_shifted_argmin = b
    idx =sortidx[grp_shifted_argmin] - b
    min_idx = idx +index
    return min_idx


min_idx =numpy_argmin_reduceat(L_list,index+1)
#printing function
DR_val_index = np.array([np.around(Drawdown,1), min_idx])
DR_result = np.apply_along_axis(lambda x: print(f'Min Values: {x[0]} at index: {x[1]}'), 0, DR_val_index)

Output

Min Values: -5 at index: 4
Min Values: 2 at index: 6
Min Values: 4 at index: 8
Min Values: 7 at index: 11

Expected Output:

Min Values: -5 at index: 5
Min Values: 2 at index: 7
Min Values: 4 at index: 9
Min Values: 7 at index: 12

1 Answer 1

0

If you change the line

id_arr[b[1:]] = 1

to

id_arr[b] = 1

I think the function will behave as you hope.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi I have edited the question could you take a look at it again. I am having another issue , with the alteration of the indexes
Don't alter questions, since that invalidates the work people put into answering them: ask new ones. On a side note, what's the source of the argmin function you have? It looks familiar :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.