numpy.nanvar(arr, axis = None) : Compute the variance of the given data (array elements) along the specified axis(if any), while ignoring NaN values.
x = 1 1 1 1 1
Standard Deviation = 0 . Variance = 0
y = 9, 2, 5, 4, 12, 7, 8, 11, 9, 3, 7, 4, 12, 5, 4, 10, 9, 6, 9, 4
Step 1 : Mean of distribution 4 = 7
Step 2 : Summation of (x – x.mean())**2 = 178
Step 3 : Finding Mean = 178 /20 = 8.9
This Result is Variance.
arr : [array_like] input array.
axis : [int or tuples of int]axis along which we want to calculate the variance. Otherwise, it will consider
arrto be flattened (works on all the axis). axis = 0 means variance along the column and axis = 1 means variance along the row.
out : [ndarray, optional]Different array in which we want to place the result. The array must have the same dimensions as expected output.
dtype : [data-type, optional]Type we desire while computing variance.
Results : Variance of the array (a scalar value if axis is none) or array with variance values along specified axis; while ignoring NaN values.
arr : [20, 2, nan, 1, 34] nanvar of arr : 187.1875 var of arr : nan nanvar of arr : 187.1875 var of arr : nan
nanvar of arr, axis = None : 249.88888888888889 var of arr, axis = None : nan nanvar of arr, axis = 0 : [ 74.88888889 312.75 458.66666667 9.25 0. ] var of arr, axis = 0 : [ nan 312.75 nan 9.25 0. ] nanvar of arr, axis = 1 : [ 0. 22.1875 421.84 313.1875]
- Python | Index of Non-Zero elements in Python list
- Python | Merge Python key values to list
- Python | Convert list to Python array
- Important differences between Python 2.x and Python 3.x with examples
- Reading Python File-Like Objects from C | Python
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Visualizing O(n) using Python
- Any & All in Python
- Python vs PHP
- max() and min() in Python
- Python Set | pop()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.