Created
December 3, 2020 16:45
-
-
Save asifr/bddadbed1302e5007e2a5b1ccfff6daa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def ffill(arr: np.ndarray): | |
arr = arr.T | |
mask = np.isnan(arr) | |
idx = np.where(~mask, np.arange(mask.shape[1]), 0) | |
np.maximum.accumulate(idx, axis=1, out=idx) | |
out = arr[np.arange(idx.shape[0])[:, None], idx].T | |
return out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment