I need to calculate array Z having array D (only using indexing, slicing and broadcasting, NO LOOPS):
D = [0, 0, 0, 0, 12, 36, 24, 24, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 36]
Z = [nan, nan, nan, nan, 12., 14.4, 15.36, 16.224, 16.224, 16.224, 16.224, 16.224, 16.224, 16.224, 16.224, 15.8016, 15.8016, 15.8016, 15.8016, 17.8214]
Rule#1: Before first non-zero value of D (here index < 4) => array Z values equal nan (here indices 0 to 3)
Rule#2: First non-zero value of D (here index 4, value 12) => array Z gets the value of A at that index (12)
Rule#3: Following Rule#2, if D is not equal to 0 at index i => Z[i] = Z[i-1] + 0.1 * (D[i] - Z[i-1])
ie:
ind=4: D[4]=12 => Z[4]=12 (Rule#2)
ind=5: D[5]=36 => Z[5]=12 + 0.1 * (36 - 12) = 14.4
ind=6: D[6]=24 => Z[6]=14.4 + 0.1 * (24 - 14.4) = 15.36
ind=7: D[7]=24 => Z[7]=15.36 + 0.1 * (24 - 15.36) = 16.224
Rule#4: If D is equal to 0 (here indice i = 8) => Z[i] = Z[i-1]
ie:
ind=8: D[8]=0 => D[8]=D[7]=16.224