With the help of choice() method, we can get the random samples of one dimensional array and return the random samples of numpy array.
Syntax : numpy.random.choice(a, size=None, replace=True, p=None)
1) a – 1-D array of numpy having random samples.
2) size – Output shape of random samples of numpy array.
3) replace – Whether the sample is with or without replacement.
4) p – The probability attach with every samples in a.
Output : Return the numpy array of random samples.
Example #1 :
In this example we can see that by using choice() method, we are able to get the random samples of numpy array, it can generate uniform or non-uniform samples by using this method.
Example #2 :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.