The problem is that the list of tuples is interpreted as a 2D array, and choice only works with 1D arrays or integers (interpreted as "select from range"). See the documentation .
So, one way to fix this is to pass the len list of tuples, and then select the elements with the appropriate index (or indices), as described in another answer . If you first include lista_elegir in np.array , this will also work for multiple indexes. However, there are two more problems:
First, the way you call the function, probabilit will be interpreted as the third replace parameter, and not as probabilities, i.e. the list is interpreted as logical, which means that you select with a replacement, but the actual probabilities are ignored. You can easily check this by passing the third parameter as [1, 0, 0] . Use p=probabilit instead. Secondly, the probabilities must be added up to 1, exactly. You only have 0.999 . It seems that you will have to slightly distort the probabilities or just leave this parameter as None if they are all the same (an even distribution is assumed).
>>> probabilit = [0.333, 0.333, 0.333] >>> lista_elegir = np.array([(3, 3), (3, 4), (3, 5)]) # for multiple indices >>> indices = np.random.choice(len(lista_elegir), 2, p=probabilit if len(set(probabilit)) > 1 else None) >>> lista_elegir[indices] array([[3, 4], [3, 5]])
source share