Editor

Create Your First NumPy Array

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 a NumPy array called temps containing the values 72.1, 68.5, 75.3, 80.0, 77.8 (daily temperatures). Print the array, its dtype, and its shape on separate lines.

import numpy as np
# Create the temps array
# Print the array, dtype, and shape

More NumPy Array exercises

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