Like :func:`get_mean` but for median.
550452
def get_median(data_np):
    """"""
    i = np.isfinite(data_np)
    if not np.any(i):
        return np.nan
    return np.median(data_np[i])
1317803
def compute_balance_mean(self, ts, t):
        
        """ For changed words we expect an increase in the mean, and so only 1 """
        return np.mean(ts[t + 1:]) - np.mean(ts[:t + 1])
538090
def extract_mean_or_value(cls, obs_or_pred, key=None):
        

        result = None
        if not isinstance(obs_or_pred, dict):
            result = obs_or_pred
        else:
            keys = ([key] if key is not None else []) + ['mean', 'value']
            for k in keys:
                if k in obs_or_pred:
                    result = obs_or_pred[k]
                    break
            if result is None:
                raise KeyError(("%s has neither a mean nor a single "
                                "value" % obs_or_pred))
        return result
265928
def median(self, func=lambda x: x):
        
        if self.count() == 0:
            raise NoElementsError(u"Iterable contains no elements")
        result = self.order_by(func).select(func).to_list()
        length = len(result)
        i = int(length / 2)
        return result[i] if length % 2 == 1 else (float(result[i - 1]) + float(result[i])) / float(2)
813175
def weighted_median(data, weights=None):
    """"""
    if weights is None:
        return median(data)
    midpoint = 0.5 * sum(weights)
    if any([j > midpoint for j in weights]):
        return data[weights.index(max(weights))]
    if any([j > 0 for j in weights]):
        sorted_data, sorted_weights = zip(*sorted(zip(data, weights)))
        cumulative_weight = 0
        below_midpoint_index = 0
        while cumulative_weight <= midpoint:
            below_midpoint_index += 1
            cumulative_weight += sorted_weights[below_midpoint_index-1]
        cumulative_weight -= sorted_weights[below_midpoint_index-1]
        if cumulative_weight - midpoint < sys.float_info.epsilon:
            bounds = sorted_data[below_midpoint_index-2:below_midpoint_index]
            return sum(bounds) / float(len(bounds))
        return sorted_data[below_midpoint_index-1]
68637
function median( out, x ) {
	var len = x.length,
		i;
	if ( out.length !== len ) {
		throw new Error( 'median()::invalid input arguments. Input and output matrices must be the same length.' );
	}
	for ( i = 0; i < len; i++ ) {
		out.data[ i ] = MEDIAN( x.data[ i ] );
	}
	return out;
}
852556
def mean(self, axis=0, *args, **kwargs):
        
        nv.validate_mean(args, kwargs)
        valid_vals = self._valid_sp_values
        sp_sum = valid_vals.sum()
        ct = len(valid_vals)

        if self._null_fill_value:
            return sp_sum / ct
        else:
            nsparse = self.sp_index.ngaps
            return (sp_sum + self.fill_value * nsparse) / (ct + nsparse)
282842
def variance(data, data_mean=None):
    
    data_mean = data_mean or mean(data)
    return sum((x - data_mean) ** 2 for x in data) / len(data)
528261
def get_val(self, x):
        """"""
        interval, mean, std = self.probability_map[x]
        new_val = norm.rvs(mean, std)
        return new_val
960127
def median(data, freq_col=1):
    

    nr_data = _nr_data(data, freq_col)
    median_idx = nr_data / 2
    i = 0
    for d in data:
        i += d[freq_col]
        if i >= median_idx:
            return d
    raise Exception("??? median ???")
750871
def median_date(dt_list):
    
    #dt_list_sort = sorted(dt_list)
    idx = len(dt_list)/2
    if len(dt_list) % 2 == 0:
        md = mean_date([dt_list[idx-1], dt_list[idx]])
    else:
        md = dt_list[idx]
    return md
1260699
def mean(name, num, minimum=0, maximum=0, ref=None):
    '''
    
    '''
    return calc(
        name=name,
        num=num,
        oper='mean',
        minimum=minimum,
        maximum=maximum,
        ref=ref
    )
689728
def mean(values: Sequence[Union[int, float, None]]) -> Optional[float]:
    
    total = 0.0  # starting with "0.0" causes automatic conversion to float
    n = 0
    for x in values:
        if x is not None:
            total += x
            n += 1
    return total / n if n > 0 else None
524166
def median(data):
    
    data = sorted(data)
    n = len(data)
    if n == 0:
        raise StatisticsError("no median for empty data")
    if n % 2 == 1:
        return data[n // 2]
    else:
        i = n // 2
        return (data[i - 1] + data[i]) / 2
835171
def mean(self):
        """"""
        # XXX rename this method
        if len(self.values) > 0:
            return sorted(self.values)[len(self.values) / 2]
        else:
            return None
551997
def mean_field(self):
        """"""
        mean_field = []
        for sp_oper in [self.oper['O'], self.oper['O_d']]:
            avgO = np.array([self.expected(op) for op in sp_oper])
            avgO[abs(avgO) < 1e-10] = 0.
            mean_field.append(avgO*self.param['ekin'])

        return np.array(mean_field)
215923
def mean(self):
    """"""
    if len(self) == 0:
      return float('NaN')
    arr = self.samples()
    return sum(arr) / float(len(arr))