Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Random number matrix within a specified range in Python

I would like to generate a random number matrix within a specified range, say (0,1).

import numpy as np
A=np.random.random((3, 3))
print("A =",[A])

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

numpy.random.uniform can receive low, high and size parameters

Range 0-1 is the default

A = np.random.uniform(size=(3, 3))
print("A =", [A])

Output

A = [array([[0.76679099, 0.57459256, 0.07952816],
            [0.02736909, 0.05905416, 0.09909474],
            [0.08690106, 0.81983883, 0.18740471]])]

If you want another range specify it with parameters

A = np.random.uniform(0.2, 0.3, (3, 3))
print("A =", [A]) 

Output

A = [array([[0.20548205, 0.25373507, 0.28957419],
            [0.20496673, 0.27004844, 0.28633947],
            [0.22325187, 0.26327935, 0.24548129]])]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading