Premium problem148. Forward-Fill Missing Values

Medium Locked

Given a 1-D float array possibly containing np.nan, return a copy where each NaN is replaced by the most recent preceding non-NaN value. Leading NaNs, before any observation, stay NaN.

Input

[nan  1. nan nan  5. nan]

Output

[nan  1.  1.  1.  5.  5.]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)