You can use numpy.nansum to calculate the norm and ignore nan:
In [54]: x Out[54]: array([ 1., 2., nan, 3.])
Here the norm with nan ignored:
In [55]: np.sqrt(np.nansum(np.square(x))) Out[55]: 3.7416573867739413
y is a normalized array:
In [56]: y = x / np.sqrt(np.nansum(np.square(x))) In [57]: y Out[57]: array([ 0.26726124, 0.53452248, nan, 0.80178373]) In [58]: np.linalg.norm(y[~np.isnan(y)]) Out[58]: 1.0
source share