import numpy as np
foo_array = [38, 26, 14, 55, 31, 0, 15, 8, 0, 0, 0, 18, 40, 27, 3, 19, 0, 
    49, 29, 21, 5, 38, 29, 17, 16]
foo = np.array(foo_array)
m = np.median(foo[foo > 0])
foo[foo == 0] = m
replace zeroes in numpy array with the median value