Skip to content

Instantly share code, notes, and snippets.

@kcha4github
Created August 5, 2018 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcha4github/6e3645fdfde5fc430527ec0c5705ef8e to your computer and use it in GitHub Desktop.
Save kcha4github/6e3645fdfde5fc430527ec0c5705ef8e to your computer and use it in GitHub Desktop.
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