![]() |
VOOZH | about |
numpy.random.choice() function allows you to randomly select elements from an array. It’s a part of NumPy's random module and is widely used for sampling with or without replacement, shuffling data, simulations and bootstrapping.
Example:
40
Explanation: A single random element is selected from the array. In this case, 40 was picked randomly (your output may vary since it's random).
numpy.random.choice(a, size=None, replace=True, p=None)
Parameters:
Returns: A single value or an array of values based on sampling rules.
1. Pick one value
3
2. Pick multiple values (with replacement)
[30 30]
3. Sample without replacement
['a' 'c']
4. Use custom probabilities
['green' 'green' 'green']
6. Multi-dimensional output
[[1 1 1] [0 0 0]]