Reputation: 625
I have 2 numpy arrays, a
and b
. Here:
a = np.random.randint(501, size=100)
How can I randomly generate array b
of size 100 in a vectorized way such that:
b[i] > a[i]
for all values of i
.b
lies between [0, 501)
.Upvotes: 3
Views: 498
Reputation: 53119
numpy
supports array parameters. You can use a
as the lower boundary:
>>> rng = np.random.default_rng()
>>>
>>> a = rng.integers(501,size=10)
>>>
>>> a
array([ 82, 95, 463, 367, 257, 296, 449, 473, 202, 468])
>>>
>>> b = rng.integers(a,501)
>>>
>>> b
array([104, 153, 476, 376, 366, 391, 458, 474, 470, 499])
Upvotes: 3