We get continuous uniform random numbers over an interval ( below ).
dimension | Int, optional , the dimension of returned array |
Output is an array of numbers.
Example 1
import numpy as np
my_data=np.random.random_sample()
print(my_data) # 0.8541225764575974
Example 2
my_data=np.random.random_sample(size=(2,3))
Output
[[0.48039485 0.87647483 0.02363604]
[0.29335428 0.46199051 0.68764865]]
Example 3
my_data=np.random.random_sample(size=(2,3,1))
Output
[[[0.8713458 ]
[0.98421453]
[0.69791198]]
[[0.5539756 ]
[0.71706405]
[0.22790952]]]
Using an interval
# over a interval 5,8
import numpy as np
my_data=(8-5)*np.random.random_sample(size=(2,3))+5
print(my_data)
Output
[[6.65899659 5.75375084 7.45066966]
[7.99360791 7.88499591 5.07648928]]
range -3,2
# over a interval -3,2
import numpy as np
my_data=(2-(-3))*np.random.random_sample(size=(2,3))-3
print(my_data)
Output
[[-2.16590208 -1.1939938 -0.95480836]
[ 1.8298811 0.12518495 -1.02893354]]
«Numpy
random.randint , Random Integers
← Subscribe to our YouTube Channel here