lundi 22 janvier 2018

Python : numpy.random.choice() without Numpy

For my program I need to select random strings stored in a list, with given weights. numpy.random.choice() is perfect for this situation, but unfortunately I'm stuck with Python 2.6.6, which does not support Numpy 1.7.0 and newer versions. random.choice is a Numpy 1.7.0 feature. Thus, I am looking for a simple function like this :

get_random_weighted(["foo1","foo2"],[0.7,0.3])
"foo1"

Thanks!




Aucun commentaire:

Enregistrer un commentaire