Predict the Shape
Intermediate · Predict the output · 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 lessonWhat does the following code print? Think about the shape before and after reshape.
import numpy as np
a = np.arange(1, 13)
b = a.reshape(3, -1)
print(b.shape)
print(b[1, 2])import numpy as np
a = np.arange(1, 13)
b = a.reshape(3, -1)
print(b.shape)
print(b[1, 2])
More NumPy Array exercises
- Create Your First NumPy ArrayIntermediate
- Array Factory FunctionsIntermediate
- Array IndexingIntermediate
- Slice and DiceIntermediate
- Matrix ExtractionIntermediate
- Fix the Reshape BugIntermediate
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz