samedi 23 septembre 2017

Select random item and index using numpy.random.choice()

I tried to implement the numpy.ramdom.choice() on a list, but I'm getting the following error:

ValueError: a must be 1-dimensional

I have the following list of values like: [-0.192, 0.23923, 0.8271, .... 0.229]

and I want to select one those elements randomly. I also need to retrieve the index of that random element, but I'm failing on the first step.

My code block is:

        values = []
        values.append(np.corrcoef(X, Y)[-1, :-1])

        i_column = np.random.choice(values)

Any advice with explanation is more than welcome.

Thanks




Aucun commentaire:

Enregistrer un commentaire