(ctx, x, tol=None)
return x
Chops off small real or imaginary parts, or converts
        numbers close to zero to exact zeros. The input can be a
        single number or an iterable::

            >>> from sympy.mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> chop(5+1e-10j, tol=1e-9)
            mpf('5.0')
            >>> nprint(chop([1.0, 1e-20, 3+1e-18j, -4, 2]))
            [1.0, 0.0, 3.0, -4.0, 2.0]

        The tolerance defaults to ``100*eps``.
Chops off small real or imaginary parts, or converts
        numbers close to zero to exact zeros. The input can be a
        single number or an iterable::
Chops off small real or imaginary parts or converts numbers close to zero to exact zeros . The input can be a single number or an iterable ::
def chop(ctx, x, tol=None):
        """
        Chops off small real or imaginary parts, or converts
        numbers close to zero to exact zeros. The input can be a
        single number or an iterable::

            >>> from sympy.mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> chop(5+1e-10j, tol=1e-9)
            mpf('5.0')
            >>> nprint(chop([1.0, 1e-20, 3+1e-18j, -4, 2]))
            [1.0, 0.0, 3.0, -4.0, 2.0]

        The tolerance defaults to ``100*eps``.
        """
        if tol is None:
            tol = 100*ctx.eps
        try:
            x = ctx.convert(x)
            absx = abs(x)
            if abs(x) < tol:
                return ctx.zero
            if ctx._is_complex_type(x):
                #part_tol = min(tol, absx*tol)
                part_tol = max(tol, absx*tol)
                if abs(x.imag) < part_tol:
                    return x.real
                if abs(x.real) < part_tol:
                    return ctx.mpc(0, x.imag)
        except TypeError:
            if isinstance(x, ctx.matrix):
                return x.apply(lambda a: ctx.chop(a, tol))
            if hasattr(x, "__iter__"):
                return [ctx.chop(a, tol) for a in x]
        return x
def chop ( ctx , x , tol = None ) : if tol is None : tol = 100 * ctx . eps try : x = ctx . convert ( x ) absx = abs ( x ) if abs ( x ) < tol : return ctx . zero if ctx . _is_complex_type ( x ) : #part_tol = min(tol, absx*tol) part_tol = max ( tol , absx * tol ) if abs ( x . imag ) < part_tol : return x . real if abs ( x . real ) < part_tol : return ctx . mpc ( 0 , x . imag ) except TypeError : if isinstance ( x , ctx . matrix ) : return x . apply ( lambda a : ctx . chop ( a , tol ) ) if hasattr ( x , "__iter__" ) : return [ ctx . chop ( a , tol ) for a in x ] return x