Python Practice › NumPy Programs › Program 82
First two columns
Write a NumPy program to access the first two columns of an array.
Input
[[6, 5, 7], [10, 9, 1], [7, 8, 2]]
Output
[[ 6 5] [10 9] [ 7 8]]
Approach
a[:, :2].
Solution
import numpy as npa = np.array([[6, 5, 7], [10, 9, 1], [7, 8, 2]])print(a[:, :2])Output
[[ 6 5] [10 9] [ 7 8]]
Learn the concept
New to this topic? Read the lesson, then come back.