import numpy as np

def avg_positive_speed(speed):
    s = np.array(speed)
positives = s > 0
if positives.any():
    return s[positives].mean()
else:
    return 0.0
speed = [1.0, 2.0, 0.0, 3.0]
print(avg_positive_speed(speed))
print(avg_positive_speed([0.0, 0.0]))
Numpy mean with condition