I know iterating through numpy arrays is more costly than using the numpy functions. This is crucial to me since my arrays are quite large.
Please use provided code as explanation what I want to achieve
start_value = 12
start_arr = np.array([-2, -4, -60, -0.5, 2, 2, 1, 70, -2, -5, 2])
out_arr = []
ans = start_value
for i in start_arr:
if i > 0:
out_arr.append(i)
ans = i
else:
out_arr.append(ans)
out_arr = np.array(out_arr)
# [12, 12, 12, 12, 2, 2, 1, 70, 70, 70, 2]
I don't know how to tell numpy to use the "previously" assigned value in case i <= 0
. Also I can't explain the problem to my browser's search engine in a way it outputs something useful.