O'Reilly logo

NumPy Cookbook - Second Edition by Ivan Idris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Random sampling with numpy.random.choice()

Bootstrapping is a procedure similar to jackknifing. The basic bootstrapping method has the following steps:

  1. Generate samples from the original data of size N. Visualize the original data sample as a bowl of numbers. We create new samples by taking numbers at random from the bowl. After taking a number, we return it to the bowl.
  2. For each generated sample, we compute the statistical estimator of interest (for example, the arithmetic mean).

How to do it...

We will apply numpy.random.choice() to do bootstrapping:

  1. Generate a data sample following the binomial distribution that simulates flipping a fair coin five times:
    N = 400
    np.random.seed(28)
    data = np.random.binomial(5, .5, size=N)
  2. Generate 30 samples and compute ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required