def co(amplitude, att_coeff, rel_coeff):
    state = 0
for sample in amplitude:
    if sample == 1.0:
        state = (1.0 - att_coeff) * sample + att_coeff * state
else:
    state = (1.0 - rel_coeff) * sample + rel_coeff * state
Fast Iteration of numpy arrays