random.randint to get random integers
We get random integers or array of random integers based on the supplied parameters ( below ).
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 |
Output is integer or array of integers based on the input parameters.
Example with low
import numpy as np
my_data=np.random.randint(4)
print(my_data) #3
Example with low and high value
my_data=np.random.randint(4,10) # 8
With low, high and size
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]]
Using dtype
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]]
Random RGB colour generator
color = tuple(np.random.choice(range(256), size=3))
«Numpy
rand() randn()
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com