mercredi 17 juin 2015

How to generate random pairs of numbers in Python, including pairs with one entry being the same and excluding pairs with both entries being the same?

I'm using Python and was using numpy for this. I want to generate pairs of random numbers. I want to exclude repetitive outcomes of pairs with both entries being the same number and I want to include pairs which only have one entry being the same number.I tried to use

import numpy
numpy.random.choice(a,(m,n),replace=False) 

for it, but it excludes any tupels with the the same entries completely, i.e.

import numpy
numpy.random.choice(a=2,(m=2,n=1),replace=False) 

gives me only (1,0) and (0,1) and not (1,1), (0,0), (1,0) and (0,1).

I want to do this because I want to draw a sample of random tuples with a large a and large n(as used above) without getting exactly the same tupels more then once. It also should be more or less efficient. Is there a way that's already implemented to do this?




Aucun commentaire:

Enregistrer un commentaire