How to use a conditional statement along with np.random.choice

90 views Asked by At

I am using np.random.choice to create 2 uniformly distributed samples from 2 provided arrays:

arr1 = np.arange(1000, 5001, 500)
arr2 = np.arange(1000, 3001, 500)

op1 = np.random.choice(arr1, 100)
op2 = np.random.choice(arr2, 100)

However, for the outputs (op1 and op2) I would like to enforce a condition so that op1[i]>=op2[i]. Is there a way I can incorporate this condition with np.random.choice, so I still get a random uniform distribution in op1 and op2, with op1[i] >= op2[i]? thanks!

1

There are 1 answers

1
BehRouz On

Check if the condition is not met for all indices and regenerate a new choice if it is not.

for i in range(100):
    while op1[i] < op2[i]:
        op2[i] = np.random.choice(arr2)