Is there any way to make this work? Where the array I'm working on consist of None
, which means to ignore that value in the processing. For example, I would like to normalize this array:
output = np.array([[1,2,None,4,5],[None,7,8,9,10]])
mu = np.mean(output, axis=(0,1), keepdims=True)
sd = np.std(output, axis=(0,1), keepdims=True)
normalized_output = (output - mu)/sd
Expected outcome:
array([[-1.5666989 , -1.21854359, None, -0.52223297, -0.17407766],
[ None, 0.52223297, 0.87038828, 1.21854359, 1.5666989 ]])
Edit: As suggested, it is better to use NaN instead of None. How to get this to work with NaN:
output = np.array([[1,2,np.NAN,4,5],[np.NAN,7,8,9,10]])
mu = np.mean(output, axis=(0,1), keepdims=True)
sd = np.std(output, axis=(0,1), keepdims=True)
normalized_output = (output - mu)/sd
print(normalized_output)
# array([[nan, nan, nan, nan, nan],
# [nan, nan, nan, nan, nan]])