I have a NumPy array a like the following:
a
>>> str(a) \'[ nan nan nan 1.44955726 1.44628034 1.44409573\\n 1.4408
I got something like this
i = [i for i in range(len(a)) if not np.isnan(a[i])] a = [a[i[0]] if x < i[0] else (a[i[-1]] if x > i[-1] else a[x]) for x in range(len(a))]
It's a bit clunky though given it's split up in two lines with nested inline if's in one of them.