I need to sample k numbers in [-n,-1] union [1,n] without replacement. Why doesn't this code work?
random.sample(range(-n,n+1).remove(0),k)
I get
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/lib/python2.7/random.py", line 319, in sample
n = len(population)
TypeError: object of type 'NoneType' has no len()
Aucun commentaire:
Enregistrer un commentaire