Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import numpy as np
chars = np.array(['a', 'b', 'c', 'd', 'e', 'f'])
mask1 = np.random.choice(6, 4)
mask2 = np.random.choice(6, 4, replace=False)
print(mask1) # ex:[4 5 0 5]
print(chars[mask1]) # ex:['e' 'f' 'a' 'f']
print(mask2) # ex:[0 5 4 2]
print(chars[mask2]) # ex:['a' 'f' 'e' 'c']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment