w3resource

NumPy: Generate an array of 15 random numbers from a standard normal distribution

NumPy: Basic Exercise-18 with Solution

Write a NumPy program to generate an array of 15 random numbers from a standard normal distribution.

Sample Solution :

Python Code :

import numpy as np
rand_num = np.random.normal(0,1,15)
print("15 random numbers from a standard normal distribution:")
print(rand_num)

Sample Output:

15 random numbers from a standard normal distribution:
[ 0.42690788  1.81615544  0.36591912 -0.41417837 -1.13061369 -1.31777265
  0.03659045  0.60765805 -0.2148491   0.25934697 -0.89221431  0.33059367
 -0.59079163  0.29665161 -0.2753327 ]                         

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to generate a random number between 0 and 1.
Next: Write a NumPy program to create a vector with values ​​ranging from 15 to 55 and print all values ​​except the first and last.

What is the difficulty level of this exercise?



Inviting useful, relevant, well-written and unique guest posts