jeudi 14 mai 2020

Generating multiple pairs of unequal random integers in python/numpy

In the context of a Monte Carlo simulation I am generating pairs of random indices, using

ij = np.random.randint(0, N, (n,2))

where n can be quite large (e.g. 10**6). I then loop over these pairs.

Issue:
I would like the numbers in each pair to be different.

The solutions that I found (e.g., using random.sample or np.random.choice) suggest generating number pair by pair. In my case it means calling the random numbers generator repeatedly in a loop, which slows down the code.




Aucun commentaire:

Enregistrer un commentaire