Let’s see how to generate random matrix in Numpy Python library.
Using Random Rand method
To generate Numpy matrix populated with random numbers use random Numpy module.
import numpy as np random_array = np.random.rand(3, 3) print(random_array)
As you can see rand function syntax require just to provide number of rows and colums.
Using Random Randint method
However there is also a possibility to generate array different way. You are able to populate your array with integers in given range. Numpy randint function allows you to do that.
import numpy as np random_array = np.random.randint(0, 7, size=10) print(random_array)
Based on this code you probably know. 0 is low value and 7 is max one. Size of array is 10.