Home > Software engineering >  How to access index in an array
How to access index in an array

Time:07-26

I would like to access indices instead of element value

import numpy as np

data=np.arange(20,60)
def number_of_dies_probed(inp_arr)-> np.array:

    inp_arr=inp_arr.flatten()
    enter_numbers=int(input('Enter number of dices to be probed:'))#for example input value 8
    vb=((len(inp_arr))/enter_numbers)

    dies_to_probe=(inp_arr[np.arange(0,inp_arr.shape[0],int(vb))])
    return dies_to_probe
mn=number_of_dies_probed(data)
print(mn)

current output:

 [20 25 30 35 40 45 50 55]   

requirement:instead of element values I need index values like this below. required output:

[0,5,10,15,20,25,30,35]

CodePudding user response:

return np.in1d(inp_arr, dies_to_probe).nonzero()[0]

returns:
array([ 0,  5, 10, 15, 20, 25, 30, 35], dtype=int64)
  • Related