low | Int, Lowest integer ( inclusive ) returned |
high | Int,Optional, Highest value ( exclusive ) returned |
size | Int,Optional, int or tupple of ints of returned |
dtype | Dtype,Optional, Data Type of returned |
import numpy as np
my_data=np.random.randint(4)
print(my_data) #3
my_data=np.random.randint(4,10) # 8
my_data=np.random.randint(4,10,size=5)
print(my_data)
Output
[6 4 4 4 5]
We will use one tuple as size parameter
my_data=np.random.randint(4,high=10,size=(3,2))
print(my_data)
Output
[[5 8]
[8 7]
[5 6]]
import numpy as np
my_data=np.random.randint(4,high=7,size=(3,3),dtype='int16')
print(my_data)
Output
[[6 4 5]
[5 6 6]
[4 6 5]]
color = tuple(np.random.choice(range(256), size=3))
Numpy rand() randn()
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.