lundi 20 mars 2017

Python: Drawing random floating point numbers excluding some interval

I want to draw say 10 floating point numbers between 0. and 2*np.pi that are not in the range (np.radians(101),np.radians(298)). The brute force method is

rand_ra=[]
while len(rand_ra) <= 10:
    x=np.random.uniform(0.,2*np.pi,100) #pick 100 or whatever number you want
    for y in x :
        if 0. <= y <= np.radians(101) and np.radians(298)<=y<= 2.*np.pi :
             rand_ra.append(y)

print rand_ra

But this is super slow, because the excluded region is so large. Is there any less time consuming method?

Thanks!




Aucun commentaire:

Enregistrer un commentaire