dimension | Int, optional , the dimension of returned array |
import numpy as np
my_data=np.random.random_sample()
print(my_data) # 0.8541225764575974
my_data=np.random.random_sample(size=(2,3))
Output
[[0.48039485 0.87647483 0.02363604]
[0.29335428 0.46199051 0.68764865]]
my_data=np.random.random_sample(size=(2,3,1))
Output
[[[0.8713458 ]
[0.98421453]
[0.69791198]]
[[0.5539756 ]
[0.71706405]
[0.22790952]]]
# 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]]
# 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
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.