<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 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: [1, q0, q0^2] 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)