Python Practice › NumPy Programs › Program 82

First two columns

EasyNumPy Programs · 82 of 100

Write a NumPy program to access the first two columns of an array.

Advertisement
Input
[[6, 5, 7], [10, 9, 1], [7, 8, 2]]
Output
[[ 6  5]
 [10  9]
 [ 7  8]]

Approach

  1. a[:, :2].

Solution

Python
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.

More numpy programs

← All 100 NumPy Programs

Leave a Comment