random.rand to get random numbers

We get random number of uniform distribution.
dimensionInt, optional , the dimension of returned array
Output is the array of given shape

Example without dimension

import numpy as np
my_data=np.random.rand()
print(my_data) # 0.6601852461443163

Example with dimension

import numpy as np
my_data=np.random.rand(4)
print(my_data)
Output
[0.97823719 0.63318689 0.6091805  0.75746223]
import numpy as np
my_data=np.random.rand(4,3)
print(my_data)
Output
[[0.22050011 0.19774343 0.89542465]
 [0.35511363 0.76718542 0.65659122]
 [0.83884429 0.80796616 0.18510076]
 [0.85687065 0.21390647 0.83901793]]
import numpy as np
my_data=np.random.rand(1,2,3,4)
print(my_data)
Output
[[[[0.58082049 0.27719339 0.67736131 0.13333281]
   [0.22314567 0.76669328 0.49681767 0.72167221]
   [0.3233574  0.99742718 0.59929845 0.85654149]]

  [[0.60382161 0.31731253 0.74987002 0.07814571]
   [0.20946435 0.740648   0.48045316 0.9641322 ]
   [0.09219005 0.05010937 0.69697473 0.66450636]]]]
Numpy random.randint , Random Integers rand()
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer