Oct-05-2021, 06:16 PM
Assuming it is a numpy array.
import numpy as np notadict = np.array([438.4, 439.18, 439.9, np.nan, np.nan]) print(notadict[(~np.isnan(notadict))], notadict) print(np.delete(notadict, np.isnan(notadict)), notadict) print(np.nan_to_num(notadict, nan=0.0), notadict) print(np.nan_to_num(notadict, copy=False, nan=0.0), notadict)
Output:[438.4 439.18 439.9 ] [438.4 439.18 439.9 nan nan]
[438.4 439.18 439.9 ] [438.4 439.18 439.9 nan nan]
[438.4 439.18 439.9 0. 0. ] [438.4 439.18 439.9 nan nan]
[438.4 439.18 439.9 0. 0. ] [438.4 439.18 439.9 0. 0. ]
Notice that nan_to_num does the change in place if you use "copy=False".