Python Practice › NumPy Programs › Program 48

Numbers greater than a value

EasyNumPy Programs · 48 of 100

Write a NumPy program to extract numbers greater than 6.

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

Approach

  1. A boolean mask.

Solution

Python
import numpy as npa = np.array([[6, 5], [10, 9], [7, 8]])print(a[a > 6])
Output
[10  9  7  8]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More numpy programs

← All 100 NumPy Programs