Skip to content

Instantly share code, notes, and snippets.

@bl4ck5un
Created September 24, 2015 21:59
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 bl4ck5un/78c2289ae0f38dd49a45 to your computer and use it in GitHub Desktop.
Save bl4ck5un/78c2289ae0f38dd49a45 to your computer and use it in GitHub Desktop.
Sample from two array coherently
# x = ...
# y = ...
idx = np.random.choice(np.arange(len(x)), 1000, replace=False)
x_sample = x[idx]
y_sample = y[idx]
"""
a : 1-D array-like or int
If an ndarray, a random sample is generated from its elements. If an int, the random sample is generated as if a was np.arange(n)
size : int or tuple of ints, optional
Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
replace : boolean, optional
Whether the sample is with or without replacement
p : 1-D array-like, optional
The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment