Python Practice › NumPy Programs › Program 67

Median of each row

EasyNumPy Programs · 67 of 100

Write a NumPy program to find the median of each row.

Advertisement
Input
[[4, 8, 1], [2, 9, 6]]
Output
[4. 6.]

Approach

  1. axis=1.

Solution

Python
import numpy as npprint(np.median(np.array([[4, 8, 1], [2, 9, 6]]), axis=1))
Output
[4. 6.]
Advertisement

Learn the concept

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

More numpy programs

← All 100 NumPy Programs