Matrix Extraction
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 lessonCreate a 4x4 matrix of numbers 1 through 16 using arange and reshape. Then print:
1. The entire second row
2. The entire third column
3. The 2x2 submatrix from the bottom-right corner
import numpy as np
# Create 4x4 matrix (1 to 16)
# Print second row, third column, bottom-right 2x2
More NumPy Array exercises
- Create Your First NumPy ArrayIntermediate
- Array Factory FunctionsIntermediate
- Array IndexingIntermediate
- Slice and DiceIntermediate
- Predict the ShapeIntermediate
- Fix the Reshape BugIntermediate
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz