lundi 26 avril 2021

Generate numpy array of random integers within a range and some fixed integers outside the defined range

I want to combine two random number generator.

I want to generate size = 20 random integers between [-5,5] and a fixed integer -999.

I tried following code:

from random import randint, choice  
import numpy as np
np.random.seed(1)
dd = np.array([choice([randint(-999,-999),randint(-5,5)]) for _ in range(20)])
print(dd)

Result:

[-999 -999 -999   -4 -999 -999   -4 -999 -999    3    5   -3    2    0
   -1 -999 -999   -5 -999   -4]

Is there any better way to generate random integers? The result with current code has many -999 due to same upper and lower limit.




Aucun commentaire:

Enregistrer un commentaire