how to get the index of numpy.random.choice? - python

前端 未结 8 1407
粉色の甜心
粉色の甜心 2021-02-02 12:31

Is it possible to modify the numpy.random.choice function in order to make it return the index of the chosen element? Basically, I want to create a list and select elements ran

8条回答
  •  故里飘歌
    2021-02-02 12:48

    Here is a simple solution, just choose from the range function.

    import numpy as np
    a = [100,400,100,300,300,200,100,400]
    I=np.random.choice(np.arange(len(a)))
    print('index is '+str(I)+' number is '+str(a[I]))
    

提交回复
热议问题