Python Practice › NumPy Programs › Program 83
Top-left 2 × 2 block
Write a NumPy program to extract the first and second elements of the first and second rows.
Input
[[6, 5, 7], [10, 9, 1], [7, 8, 2]]
Output
[[ 6 5] [10 9]]
Approach
a[:2, :2].
Solution
import numpy as npa = np.array([[6, 5, 7], [10, 9, 1], [7, 8, 2]])print(a[:2, :2])Output
[[ 6 5] [10 9]]
Learn the concept
New to this topic? Read the lesson, then come back.