Reduction function with given operation.

    Args:
        x (Variable): An input.
        op (str): 'sum' or 'mean'.

    Note:
        This is deprecated. Use ``mean`` or ``sum`` instead.
558892
def reduce(x, op='sum'):
    
    import warnings
    warnings.warn(
        "Deprecated API. Use ``sum`` or ``mean`` instead.", DeprecationWarning)
    from .function_bases import reduce_sum, reduce_mean
    if op == 'sum':
        return reduce_sum(x)
    elif op == 'mean':
        return reduce_mean(x)
    raise ValueError()
376783
function sum(x) {
        var value = 0;
        for (var i = 0; i < x.length; i++) {
            value += x[i];
        }
        return value;
    }
652467
def reduce_sum_square(attrs, inputs, proto_obj):
    """"""
    square_op = symbol.square(inputs[0])
    sum_op = symbol.sum(square_op, axis=attrs.get('axes'),
                        keepdims=attrs.get('keepdims'))
    return sum_op, attrs, inputs
744825
def trunc(x):
    
    if isinstance(x, UncertainFunction):
        mcpts = np.trunc(x._mcpts)
        return UncertainFunction(mcpts)
    else:
        return np.trunc(x)
111447
def mean(self, **kwargs):
        
        if self._is_transposed:
            kwargs["axis"] = kwargs.get("axis", 0) ^ 1
            return self.transpose().mean(**kwargs)
        # Pandas default is 0 (though not mentioned in docs)
        axis = kwargs.get("axis", 0)
        sums = self.sum(**kwargs)
        counts = self.count(axis=axis, numeric_only=kwargs.get("numeric_only", None))
        if sums._is_transposed and counts._is_transposed:
            sums = sums.transpose()
            counts = counts.transpose()
        result = sums.binary_op("truediv", counts, axis=axis)
        return result.transpose() if axis == 0 else result
1009060
def _function(self, x, a, b, c, d):
        
        return c/((a**2-x**2)**2 + (b*x)**2)+d
949899
def count_above_mean(x):
    
    m = np.mean(x)
    return np.where(x > m)[0].size
2058
def _value_function(self, x_input, y_true, y_pred):
        
        if len(y_true.shape) == 1:
            return y_pred.argmax(1).eq(y_true).double().mean().item()
        else:
            raise NotImplementedError
619379
def _call(self, x, out=None):
        """"""
        if out is None:
            return self.operator(x * self.vector)
        else:
            tmp = self.domain.element()
            x.multiply(self.vector, out=tmp)
            self.operator(tmp, out=out)
781548
def ex(mt, x):
    
    sum1 = 0
    for j in mt.lx[x + 1:-1]:
        sum1 += j
        #print sum1
    try:
        return sum1 / mt.lx[x] + 0.5
    except:
        return 0
674737
def ai(x, context=None):
    
    return _apply_function_in_current_context(
        BigFloat,
        mpfr.mpfr_ai,
        (BigFloat._implicit_convert(x),),
        context,
    )
289986
def erf(x):
    
    try:
        return math.erf(x)
    except TypeError:
        pass
    if isinstance(x, GVar):
        f = math.erf(x.mean)
        dfdx = 2. * math.exp(- x.mean ** 2) / math.sqrt(math.pi)
        return gvar_function(x, f, dfdx)
    else:
        x = numpy.asarray(x)
        ans = numpy.empty(x.shape, x.dtype)
        for i in range(x.size):
            try:
                ans.flat[i] = erf(x.flat[i])
            except TypeError:
                xi = x.flat[i]
                f = math.erf(xi.mean)
                dfdx = 2. * math.exp(- xi.mean ** 2) / math.sqrt(math.pi)
                ans.flat[i] = gvar_function(xi, f, dfdx)
        return ans
823653
def var(expr, **kw):
    

    ddof = kw.get('ddof', kw.get('_ddof', 1))

    output_type = _stats_type(expr)
    return _reduction(expr, Var, output_type, _ddof=ddof)
568505
def gt(self, value):
        
        self.op = '>'
        self.negate_op = '<='
        self.value = self._value(value)
        return self
360705
def _minimize_constraints_fun_summation(x):
    '''
    
    '''
    summation = sum([x[i] for i in CONSTRAINT_PARAMS_IDX])
    return CONSTRAINT_UPPERBOUND >= summation >= CONSTRAINT_LOWERBOUND
689529
def _call(self, x, out=None):
        """"""
        if out is None:
            return self.scalar * self.operator(x)
        else:
            self.operator(x, out=out)
            out *= self.scalar
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)