Skip to content

Instantly share code, notes, and snippets.

@ruliana
Created September 5, 2018 13:01
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 ruliana/f63541e21547a23f6e94f5de547533e0 to your computer and use it in GitHub Desktop.
Save ruliana/f63541e21547a23f6e94f5de547533e0 to your computer and use it in GitHub Desktop.
Simple bootstrapping with numpy
def bootstrap(np_array, func, n_samples=1000, size=None):
size = size if size else len(np_array)
return np.apply_along_axis(func, 1, np.random.choice(np_array, size=(n_samples, size)))
# Example use
bootstrap(some_array, np.mean)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment