1fruits = ['apple', 'banana', 'orange', 'grape']
2subset_size = int(0.7 * len(fruits))
3np.random.choice(fruits, subset_size, replace=False)
4# array(['grape', 'banana'], dtype='<U6')
1>>> np.random.choice(5, 3, replace=False)
2array([3,1,0])
3>>> #This is equivalent to np.random.permutation(np.arange(5))[:3]
4
1>>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher']
2>>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3])
3array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'],
4 dtype='|S11')
5
6
7
8fruits = ['apple', 'banana', 'orange', 'grape']
9subset_size = int(0.7 * len(fruits))
10np.random.choice(fruits, subset_size, replace=False)
11# array(['grape', 'banana'], dtype='<U6')
12