For example, take the following tensor: tf.constant([ [0, np.nan, 2, 1], [np.nan, 3, 3, 4], ]) I'd like to implement a forward-fill operation like pd.DataFrame.ffill (with axis=0). The output of the ffill operation should therefore be: [ [0, np.nan, 2, 1] [0, 3, 3, 4] ] However, it's not clear to me how I can achieve this tensor transformation. I did find the following question that addresses this for the 1D case: https://stackoverflow.com/a/52818310/1613983 However, the values variable in that implementation is a sparse representation of the input data, which works fine in one dimension, but I wasn't able to translate that to the 2D case. Continue reading...