Generate some random data with Numpy

Numpy, Python's pre-eminent mathematics library, makes it easy to generate random numeric data in the form of two-dimension arrays.

Here's one way of generating some random numeric data with Numpy.

Import Numpy

When importing numpy the standard practice is to import is as np.

import numpy as np

Build some random data in the form of a numpy array

Suppose I want to generate some random numeric data that consists of integers ranging from 0 to 99 in the form of an array that has 3 rows and five columns.

data = np.random.randint(100, size=(3,5)`

This will yield an array that looks something like this:

array([[82,  7, 92, 35,  7],
       [81, 71, 56, 80, 82],
       [55,  6, 96, 87, 83]])