Skip main navigation

Hands-on: Random numbers

Generate random numbers in an array
© CC-BY-NC-SA 4.0 by CSC - IT Center for Science

In this exercise we practice creating arrays of random numbers.

Source code for this exercise is located in numpy/random-numbers/

Generate a one dimensional 1000 element array of uniformly distributed random
numbers using the numpy.random module.

  1. Calculate the mean and standard deviation of the array using numpy.mean()
    and numpy.std().
  2. Choose some other random distribution and calculate its mean and standard
    deviation.

You can visualize the random distributions with matplotlib’s hist()
function:

import matplotlib.pyplot as plt

plt.hist(x)
plt.show()
© CC-BY-NC-SA 4.0 by CSC - IT Center for Science
This article is from the free online

Python in High Performance Computing

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now