How to choose elements from the list with different probability using NumPy?
We will see How to use numpy.random.choice() method to choose elements from the list with different probability.
Syntax: numpy.random.choice(a, size=None, replace=True, p=None)
Output: Return the numpy array of random samples.
Note: parameter p is probabilities associated with each entry in a(1d-array). If not given the sample assumes a uniform distribution over all entries in a.
Now, let’s see the examples:
[40 40 40]
In the above example, we want only to select the 3rd index element from the given list every time.
[30 40 30]
In the above example, we want to select 2nd & 3rd index elements from the given list every time.