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 & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.