Python Practice › NumPy Programs › Program 42

Find missing data

EasyNumPy Programs · 42 of 100

Write a NumPy program to find the missing (NaN) values in an array.

Advertisement
Input
[[1, 5, nan], [8, nan, 9]]
Output
[[False False  True]
 [False  True False]]
2 missing

Approach

  1. np.isnan().

Solution

Python
import numpy as npa = np.array([[1, 5, np.nan], [8, np.nan, 9]])print(np.isnan(a))print(np.isnan(a).sum(), "missing")
Output
[[False False  True]
 [False  True False]]
2 missing
Advertisement

Learn the concept

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

More numpy programs

← All 100 NumPy Programs