python - How to use numpy.random.choice in a list of tuples? -


i need random choice given probability selecting tuple list.

edit: probabiliy each tuple in probabilit list not know forget parameter replacement, default none same problem using array instead list

the next sample code give me error:

import numpy np  probabilit = [0.333, 0.333, 0.333] lista_elegir = [(3, 3), (3, 4), (3, 5)]  np.random.choice(lista_elegir, 1, probabilit) 

and error is:

valueerror: must 1-dimensional 

how can solve that?

according function's doc,

a : 1-d array-like or int     if ndarray, random sample generated elements.     if int, random sample generated if np.arange(n) 

so following that

lista_elegir[np.random.choice(len(lista_elegir),1,p=probabilit)] 

should want. (p= added per comment; can omit if values uniform).

it choosing number [0,1,2], , picking element list.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -