Making x_mean work with unequal arrays