This lesson requires a premium membership to access.
Premium membership includes unlimited access to all courses, quizzes, downloadable resources, and future content updates.
Ask questions about this lesson and get instant answers.
We learned about how to create an array using np.array(). NumPy also provides a few other methods to create new arrays.
The functions zeros and ones create new arrays of specified dimensions filled with these values (Os and 1s). These are perhaps the most commonly used functions to create new arrays:
1>>> import numpy as np
2>>> np.zeros(6)
3array([ 0., 0., 0., 0., 0., 0.])
4>>> np.zeros([2,3])
5array([[ 0., 0., 0.],
6 [ 0., 0., 0.]])
7>>> np.ones([3,3])
8array([[ 1., 1., 1.],
9 [ 1., 1., 1.],
10 [ 1., 1., 1.]])
11>>>
12