"""Useful functions."""
from functools import partial as _partial
import numpy as _np


def polyfit(x, y, monomials):
    """Implement Custom polyfit."""
    coef = _np.polynomial.polynomial.polyfit(x, y, deg=monomials)

    # finds maximum diff and its base value
    y_fitted = _np.polynomial.polynomial.polyval(x, coef)
    y_diff = abs(y_fitted - y)
    idx = _np.argmax(y_diff)

    coeffs = coef[monomials]
    return (coeffs, (y_diff[idx], y[idx]))


def generate_random_numbers(n_part, dist_type='exp', cutoff=3):
    """Generate random numbers with a cutted off dist_type distribution.

    Inputs:
        n_part = size of the array with random numbers
        dist_type = assume values 'exponential', 'normal' or 'uniform'.
        cutoff = where to cut the distribution tail.
    """
    dist_type = dist_type.lower()
    if dist_type in 'exponential':
        func = _partial(_np.random.exponential, 1)
    elif dist_type in 'normal':
        func = _np.random.randn
    elif dist_type in 'uniform':
        func = _np.random.rand
    else:
        raise NotImplementedError('Distribution type not implemented yet.')

    numbers = func(n_part)
    above, *_ = _np.asarray(_np.abs(numbers) > cutoff).nonzero()
    while above.size:
        parts = func(above.size)
        indcs = _np.abs(parts) > cutoff
        numbers[above[~indcs]] = parts[~indcs]
        above = above[indcs]
    return numbers

@@ -85,378 +85,8 @@
 p%0A%0A%0A
-def polyfit(x, y, monomials):%0A    %22%22%22Implement Custom polyfit.%22%22%22%0A    coef = _np.polynomial.polynomial.polyfit(x, y, deg=monomials)%0A%0A    # finds maximum diff and its base value%0A    y_fitted = _np.polynomial.polynomial.polyval(x, coef)%0A    y_diff = abs(y_fitted - y)%0A    idx = _np.argmax(y_diff)%0A%0A    coeffs = coef%5Bmonomials%5D%0A    return (coeffs, (y_diff%5Bidx%5D, y%5Bidx%5D))%0A%0A%0A
 def 

remove method polyfit.