Generate random numbers between 1-2 using NumPy.

In this python numpy program, we will generate random numbers between 1-2 using NumPy.

Steps to solve the program
  1. From the numpy library import random.
  2. Generate random numbers between 1-2 using random.rand().
  3. Use for loop with the range function to generate 5 numbers.
  4. Print the output.
				
					from numpy import random
for i in range(5):
    rand_num = random.rand()
    print(rand_num)
				
			

Output :

				
					0.9108111865486636
0.6770944961821627
0.4528420505050911
0.7668031795361783
0.4633483035604695
				
			

create a 3×3 identify matrix.

generate an array of 5 random numbers from a standard normal distribution.

Leave a Comment