Back to Practice
#0098

Column Means Ignoring NaN

EasyNumPy15 min10 XP

Problem

Given a 2D NumPy array, return column means ignoring NaN values.

Why This Matters

NaN-aware aggregation appears in real datasets before imputation, reporting, and feature analysis.

Function Signature

def column_nanmeans(matrix):

Examples

Example 1
Input[[1, nan], [3, 5]]
Output[2, 5]

The NaN value is ignored for the second column mean.

Constraints

  • Return the exact structure requested.
  • Handle the edge cases mentioned in the prompt.
  • Prefer clear logic over clever one-liners.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input[[1, nan], [3, 5]]
Expected[2, 5]

The NaN value is ignored for the second column mean.

Hidden Test Categories
no NaN valuesmultiple NaNs in one columnfloat input