samedi 27 avril 2019

Fast way to generate samples with np.random.choice()?

I want to generate random sample without replacement for N times, like following:

import numpy as np

sample = np.zeros([100000, 4], int)
for i in range(100000):
    sample[i] = np.random.choice(128, 4, replace=False)

If the iterations become very large, the overall sampling will be time consuming. Is there any way to speed up this sampling?




Aucun commentaire:

Enregistrer un commentaire