Create two arrays in numpy with random int from a uniform distr

Question:

Each number in "a" array should be >= with the number in the same position from "b" array. Range 0,10

a = np.random.randint(0,10,300)

b=[]
for i in a:
   b = np.random.randint(0,i,300)

Got a ValueError: low >= high

Then I tried i+1 but values in b exceed the ones from a

Asked By: vartholomeos007

||

Answers:

If your goal is to create two random arrays ensuring a >= b, you can use:

b, a = np.sort(np.random.randint(0, 10, (2, 300)), axis=0)

assert (a>=b).all()
Answered By: mozway
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.