Write a NumPy program to calculate mean of array by ignoring NaN.
Source Code:
import numpy as np
ary = np.array([8,30,93,np.nan,54])
print("Array is:\n",ary)
print("Mean of given array is:",np.mean(ary))
#Calculate mean by ignoring np.nan from array use np.nanmean()
print("Mean of given array after ignoring nan is:",np.nanmean(ary))
Sample Output:ary = np.array([8,30,93,np.nan,54])
print("Array is:\n",ary)
print("Mean of given array is:",np.mean(ary))
#Calculate mean by ignoring np.nan from array use np.nanmean()
print("Mean of given array after ignoring nan is:",np.nanmean(ary))
Array is:
[ 8. 30. 93. nan 54.]
Mean of given array is: nan
Mean of given array after ignoring nan is: 46.25
[ 8. 30. 93. nan 54.]
Mean of given array is: nan
Mean of given array after ignoring nan is: 46.25