def sum(vari, axis=None): # pylint: disable=redefined-builtin
    """
    Sum the components of a shapeable quantity along a given axis.

    Args:
        vari (chaospy.poly.base.Poly, numpy.ndarray):
            Input data.
        axis (int):
            Axis over which the sum is taken. By default ``axis`` is None, and
            all elements are summed.

    Returns:
        (chaospy.poly.base.Poly, numpy.ndarray):
            Polynomial array with same shape as ``vari``, with the specified
            axis removed. If ``vari`` is an 0-d array, or ``axis`` is None,
            a (non-iterable) component is returned.

    Examples:
        >>> vari = cp.prange(3)
        >>> print(vari)
        [1, q0, q0^2]
        >>> print(cp.sum(vari))
        q0^2+q0+1
    """
    if isinstance(vari, Poly):

        core = vari.A.copy()
        for key in vari.keys:
            core[key] = sum(core[key], axis)

        return Poly(core, vari.dim, None, vari.dtype)

    return np.sum(vari, axis)