np nan to zero code example Example 1: numpy fill na with 0 import numpy as np A[np.isnan(A)] = 0 Example 2: python zeros to nan a[a==0] = np.nan