Python | numpy.nanmean() function Last Updated : 01 Jun, 2021 Comments Improve Suggest changes Like Article Like Report numpy.nanmean() function can be used to calculate the mean of array ignoring the NaN value. If array have NaN value and we can find out the mean without effect of NaN value. Syntax: numpy.nanmean(a, axis=None, dtype=None, out=None, keepdims=))Parameters: a: [arr_like] input array axis: we can use axis=1 means row wise or axis=0 means column wise. out: output array dtype: data types of array overwrite_input: If True, then allow use of memory of input array a for calculations. The input array will be modified by the call to median. keepdims: If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.Returns: Returns the average of the array elements Example #1: Python3 # Python code to demonstrate the # use of numpy.nanmean import numpy as np # create 2d array with nan value. arr = np.array([[20, 15, 37], [47, 13, np.nan]]) print("Shape of array is", arr.shape) print("Mean of array without using nanmean function:", np.mean(arr)) print("Using nanmean function:", np.nanmean(arr)) Output: Shape of array is (2, 3) Mean of array without using nanmean function: nan Using nanmean function: 26.4 Example #2: Python3 # Python code to demonstrate the # use of numpy.nanmean # with axis = 0 import numpy as np # create 2d matrix with nan value arr = np.array([[32, 20, 24], [47, 63, np.nan], [17, 28, np.nan], [10, 8, 9]]) print("Shape of array is", arr.shape) print("Mean of array with axis = 0:", np.mean(arr, axis = 0)) print("Using nanmedian function:", np.nanmean(arr, axis = 0)) Output: Shape of array is (4, 3) Mean of array with axis = 0: [ 26.5 29.75 nan] Using nanmedian function: [ 26.5 29.75 16.5 ] Example #3: Python3 # Python code to demonstrate the # use of numpy.nanmedian # with axis = 1 import numpy as np # create 2d matrix with nan value arr = np.array([[32, 20, 24], [47, 63, np.nan], [17, 28, np.nan], [10, 8, 9]]) print("Shape of array is", arr.shape) print("Mean of array with axis = 1:", np.mean(arr, axis = 1)) print("Using nanmedian function:", np.nanmean(arr, axis = 1)) Output: Shape of array is (4, 3) Mean of array with axis = 1: [ 25.33333333 nan nan 9. ] Using nanmedian function: [ 25.33333333 55. 22.5 9. ] Comment More info S shrikanth13 Follow Improve Article Tags : Python Python-numpy Python numpy-Statistics Functions Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 7 min read Python Functions 5 min read Recursion in Python 6 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 5 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like