Random sampling with replacement

To generate random sampling with replacement, follow the given steps:

  1. We can generate a random sample with replacement using the numpy.random.randint() method and drawing random integers:
sack = np.array([4, 8, -2, 7, 5])
sampler = np.random.randint(0, len(sack), size = 10)
sampler

We created the sampler using the np.random.randint() method. The output of the preceding code is as follows:

array([3, 3, 0, 4, 0, 0, 1, 2, 1, 4])
  1. And now, we can draw the required samples:
draw = sack.take(sampler)
draw

The output of the preceding code is as follows:

array([ 7,  7,  4,  5,  4,  4,  8, -2,  8,  5])

Compare the index of the sampler and then compare it with the original dataframe. The results are pretty obvious in this case. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.76.164