Answers for "numpy sample from array"

1

python select random subset from numpy array

fruits = ['apple', 'banana', 'orange', 'grape']
subset_size = int(0.7 * len(fruits))
np.random.choice(fruits, subset_size, replace=False)
# array(['grape', 'banana'], dtype='<U6')
Posted by: Guest on March-03-2020
0

random choice sampling numpy

>>> np.random.choice(5, 3, replace=False)
array([3,1,0])
>>> #This is equivalent to np.random.permutation(np.arange(5))[:3]
Posted by: Guest on June-15-2020

Python Answers by Framework

Browse Popular Code Answers by Language