Replace zeros of array with last non-zero value

Hi AFL experts,

I have an array that looks like this;

arr_with_zeros = [1 0 0 2 0 0 3 0 0 6 0 0 8 0 0]

I want to replace the zeros with the last non-zero value in the array. The new array should look like this;

arr_non_zeros = [1 1 1 2 2 2 3 3 3 6 6 6 8 8 8]

This is the code I wrote.
arr_non_zeros = ValueWhen(True, arr_with_zeros, n=1);

It does not work. arr_non_zeros has the same contents as arr_with_zeros. Can someone help? Thank you.

Dont use condition as True in ValueWhen()

use this
m2 = ValueWhen( m1 != 0, m1, 1);

1 Like