Editor

Array Factory Functions

Intermediate · Write the code · from NumPy Arrays: Create, Index, Slice, and Reshape

From the lesson: NumPy Arrays: Create, Index, Slice, and Reshape

Imagine you have a spreadsheet with a million rows of numbers and you need to multiply every single value by 2. With a regular Python list, you'd write a loop that visits each cell one by one. It works, but it's slow.

Read the lesson

Create three arrays and print each one:

1. z - an array of 6 zeros

2. o - a 2x3 array of ones

3. r - numbers from 5 to 25 (inclusive) in steps of 5 using arange

Print each array on its own line.

import numpy as np
# Create the three arrays
# Print each one

More NumPy Array exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz