mask = np.random.randint(0, 2, a.size)
b = np.ma.masked_array(a, mask=mask)
b[np.invert(b.mask)] = 1000
print((np.average(b), np.mean(b), np.ma.average(b), np.ma.mean(b)))
Numpy average from a large masked array