Numpy
Numpy (20)
Jun's N
2022. 8. 11. 21:50
How to create a 2D array containing random floats between 5 and 10?
# Input
arr = np.arange(9).reshape(3,3)
# 1:
rand_arr = np.random.randint(low=5, high=10, size=(5,3)) + np.random.random((5,3))
# print(rand_arr)
# 2:
rand_arr = np.random.uniform(5,10, size=(5,3))
print(rand_arr)
# output
[[ 8.50061025 9.10531502 6.85867783]
[ 9.76262069 9.87717411 7.13466701]
[ 7.48966403 8.33409158 6.16808631]
[ 7.75010551 9.94535696 5.27373226]
[ 8.0850361 5.56165518 7.31244004]]
728x90