dimanche 14 octobre 2018

Random numpy array in order

I have a random sampling method as below:

def costum_random_sample(size):
    randomList = []
    counter = 0
    last_n = -1
    while(size != counter):
        n = random.random()
        if abs(n - last_n) < 0.05:
            continue
        else:
            randomList.append(n)
            counter += 1
            last_n = n

    return np.array(randomList) 

The result is an array([0.50146945, 0.17442673, 0.60011469, 0.13501798]) like this. Now, I want to change it to make it resulted in order likes array in ascending order. Sort() doesn't work in this case since it change the order of my array after it is generated, and the logic between each number is changed. I want it random the number in list in order, by that way it could keep the logic in the number sequence. How can I do that?




Aucun commentaire:

Enregistrer un commentaire