How to Generate a 2-D Array of Random Floats


In this example we will show how to generate a 2-D array of random floats in Python NumPy.

Source Code

from numpy import random

# generate a 2-D array with 4 rows, each row containing 3 random floats
n = random.rand(4, 3)

print(n)

Output:

[[0.23343573 0.18152101 0.27178942]
 [0.21241472 0.61334015 0.47970094]
 [0.19512793 0.32336471 0.97855402]
 [0.61951027 0.26754547 0.43948623]]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments