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?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Python: Use Enumerate() In for Loops

>>> students = ('John', 'Mary',  'Mike')
>>> for i, student in enumerate(students):
  ...     print(f'Iteration:  {i}, Student: {student}')
  ... 
Iteration: 0, Student: John
Iteration: 1, Student: Mary
Iteration: 2, Student: Mike
>>> for i, student in enumerate(students,  35001):
  ...      print(f'Student Name: {student}, Student ID #: {i}')
  ... 
Student Name: John, Student ID #: 35001
Student Name: Mary, Student ID #: 35002
Student Name: Mike, Student ID #: 35003