5.5 Ones and zeros

Download notebook Interact
import numpy as np

We often want to create arrays with all zeros, or all ones.

We do this with:

np.zeros(5)
array([0., 0., 0., 0., 0.])
np.ones(3)
array([1., 1., 1.])

As ever, review the help with (for example):

np.ones?

In a new cell.

You can ask for a 2D array by passing a list with the numbers of rows and columns:

np.zeros([5, 2])
array([[0., 0.],
       [0., 0.],
       [0., 0.],
       [0., 0.],
       [0., 0.]])