403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.19.244.133
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib64/python3.7/site-packages/numpy/lib/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib64/python3.7/site-packages/numpy/lib/__pycache__/polynomial.cpython-37.pyc
B

��Fd]��@s`dZddlmZmZmZddddddd	d
ddd
dgZddlZddlZddlm	m
Zddlm
Z
mZmZmZmZmZmZmZddlmZmZddlmZddlmZmZmZmZddlm Z m!Z!m"Z"Gdd�de#�Z$dd�Z%dd�Z&d(dd�Z'd)dd�Z(d*dd
�Z)dd�Z*dd�Z+dd�Z,d d	�Z-d!d
�Z.e�/d"�Z0d+d$d%�Z1Gd&d�de2�Z3e�4d'e$�dS),z'
Functions to operate on polynomials.

�)�division�absolute_import�print_function�poly�roots�polyint�polyder�polyadd�polysub�polymul�polydiv�polyval�poly1d�polyfit�RankWarningN)�isscalar�abs�finfo�
atleast_1d�hstack�dot�array�ones)�diag�vander)�
trim_zeros)�	iscomplex�real�imag�mintypecode)�eigvals�lstsq�invc@seZdZdZdS)rz�
    Issued by `polyfit` when the Vandermonde matrix is rank deficient.

    For more information, a way to suppress the warning, and an example of
    `RankWarning` being issued, see `polyfit`.

    N)�__name__�
__module__�__qualname__�__doc__�r'r'�G/opt/alt/python37/lib64/python3.7/site-packages/numpy/lib/polynomial.pyrscCst|�}|j}t|�dkr@|d|dkr@|ddkr@t|�}n4t|�dkrl|j}|tkrt|�t|j��}nt	d��t|�dkr�dS|j}t
d|d�}x6tt|��D]&}tj
|td||g|d�dd	�}q�Wt|jjtj��rt�|t�}t�t�|�t�|���k��r|j��}|S)
a}
    Find the coefficients of a polynomial with the given sequence of roots.

    Returns the coefficients of the polynomial whose leading coefficient
    is one for the given sequence of zeros (multiple roots must be included
    in the sequence as many times as their multiplicity; see Examples).
    A square matrix (or array, which will be treated as a matrix) can also
    be given, in which case the coefficients of the characteristic polynomial
    of the matrix are returned.

    Parameters
    ----------
    seq_of_zeros : array_like, shape (N,) or (N, N)
        A sequence of polynomial roots, or a square array or matrix object.

    Returns
    -------
    c : ndarray
        1D array of polynomial coefficients from highest to lowest degree:

        ``c[0] * x**(N) + c[1] * x**(N-1) + ... + c[N-1] * x + c[N]``
        where c[0] always equals 1.

    Raises
    ------
    ValueError
        If input is the wrong shape (the input must be a 1-D or square
        2-D array).

    See Also
    --------
    polyval : Compute polynomial values.
    roots : Return the roots of a polynomial.
    polyfit : Least squares polynomial fit.
    poly1d : A one-dimensional polynomial class.

    Notes
    -----
    Specifying the roots of a polynomial still leaves one degree of
    freedom, typically represented by an undetermined leading
    coefficient. [1]_ In the case of this function, that coefficient -
    the first one in the returned array - is always taken as one. (If
    for some reason you have one other point, the only automatic way
    presently to leverage that information is to use ``polyfit``.)

    The characteristic polynomial, :math:`p_a(t)`, of an `n`-by-`n`
    matrix **A** is given by

        :math:`p_a(t) = \mathrm{det}(t\, \mathbf{I} - \mathbf{A})`,

    where **I** is the `n`-by-`n` identity matrix. [2]_

    References
    ----------
    .. [1] M. Sullivan and M. Sullivan, III, "Algebra and Trignometry,
       Enhanced With Graphing Utilities," Prentice-Hall, pg. 318, 1996.

    .. [2] G. Strang, "Linear Algebra and Its Applications, 2nd Edition,"
       Academic Press, pg. 182, 1980.

    Examples
    --------
    Given a sequence of a polynomial's zeros:

    >>> np.poly((0, 0, 0)) # Multiple root example
    array([1, 0, 0, 0])

    The line above represents z**3 + 0*z**2 + 0*z + 0.

    >>> np.poly((-1./2, 0, 1./2))
    array([ 1.  ,  0.  , -0.25,  0.  ])

    The line above represents z**3 - z/4

    >>> np.poly((np.random.random(1.)[0], 0, np.random.random(1.)[0]))
    array([ 1.        , -0.77086955,  0.08618131,  0.        ]) #random

    Given a square array object:

    >>> P = np.array([[0, 1./3], [-1./2, 0]])
    >>> np.poly(P)
    array([ 1.        ,  0.        ,  0.16666667])

    Or a square matrix object:

    >>> np.poly(np.matrix(P))
    array([ 1.        ,  0.        ,  0.16666667])

    Note how in all cases the leading coefficient is always 1.

    �r�z.input must be 1d or non-empty square 2d array.g�?)r*)�dtype�full)�mode)r�shape�lenr r+�object�astyper�char�
ValueErrorr�range�NX�convolver�
issubclass�type�complexfloating�asarray�complex�all�sort�	conjugater�copy)Zseq_of_zeros�sh�dt�a�krr'r'r(r s*\(
 
cCst|�}|jdkrtd��t�t�|��d}t|�dkrDt�g�St|�|dd}|t|d�t|d�d�}t	|j
jtjtj
f�s�|�t�}t|�}|dkr�tt�|df|j
�d�}|dd�|d|ddd�f<t|�}n
t�g�}t|t�||j
�f�}|S)a�
    Return the roots of a polynomial with coefficients given in p.

    The values in the rank-1 array `p` are coefficients of a polynomial.
    If the length of `p` is n+1 then the polynomial is described by::

      p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n]

    Parameters
    ----------
    p : array_like
        Rank-1 array of polynomial coefficients.

    Returns
    -------
    out : ndarray
        An array containing the roots of the polynomial.

    Raises
    ------
    ValueError
        When `p` cannot be converted to a rank-1 array.

    See also
    --------
    poly : Find the coefficients of a polynomial with a given sequence
           of roots.
    polyval : Compute polynomial values.
    polyfit : Least squares polynomial fit.
    poly1d : A one-dimensional polynomial class.

    Notes
    -----
    The algorithm relies on computing the eigenvalues of the
    companion matrix [1]_.

    References
    ----------
    .. [1] R. A. Horn & C. R. Johnson, *Matrix Analysis*.  Cambridge, UK:
        Cambridge University Press, 1999, pp. 146-7.

    Examples
    --------
    >>> coeff = [3.2, 2, 1]
    >>> np.roots(coeff)
    array([-0.3125+0.46351241j, -0.3125-0.46351241j])

    r*zInput must be a rank-1 array.r���r)N)r�ndimr3r5ZnonzeroZravelr/r�intr7r+r8Zfloatingr9r1�floatrrr r�zeros)�pZnon_zeroZtrailing_zeros�N�Arr'r'r(r�s$2

 
"

r*c	Cs�t|�}|dkrtd��|dkr,t�|t�}t|�}t|�dkr\|dkr\|dt�|t�}t|�|krptd��t|t	�}t�
|�}|dkr�|r�t	|�S|St�|�t�
t|�dd��|dgf�}t||d|dd�d�}|r�t	|�S|SdS)av
    Return an antiderivative (indefinite integral) of a polynomial.

    The returned order `m` antiderivative `P` of polynomial `p` satisfies
    :math:`\frac{d^m}{dx^m}P(x) = p(x)` and is defined up to `m - 1`
    integration constants `k`. The constants determine the low-order
    polynomial part

    .. math:: \frac{k_{m-1}}{0!} x^0 + \ldots + \frac{k_0}{(m-1)!}x^{m-1}

    of `P` so that :math:`P^{(j)}(0) = k_{m-j-1}`.

    Parameters
    ----------
    p : array_like or poly1d
        Polynomial to differentiate.
        A sequence is interpreted as polynomial coefficients, see `poly1d`.
    m : int, optional
        Order of the antiderivative. (Default: 1)
    k : list of `m` scalars or scalar, optional
        Integration constants. They are given in the order of integration:
        those corresponding to highest-order terms come first.

        If ``None`` (default), all constants are assumed to be zero.
        If `m = 1`, a single scalar can be given instead of a list.

    See Also
    --------
    polyder : derivative of a polynomial
    poly1d.integ : equivalent method

    Examples
    --------
    The defining property of the antiderivative:

    >>> p = np.poly1d([1,1,1])
    >>> P = np.polyint(p)
    >>> P
    poly1d([ 0.33333333,  0.5       ,  1.        ,  0.        ])
    >>> np.polyder(P) == p
    True

    The integration constants default to zero, but can be specified:

    >>> P = np.polyint(p, 3)
    >>> P(0)
    0.0
    >>> np.polyder(P)(0)
    0.0
    >>> np.polyder(P, 2)(0)
    0.0
    >>> P = np.polyint(p, 3, k=[6,5,3])
    >>> P
    poly1d([ 0.01666667,  0.04166667,  0.16666667,  3. ,  5. ,  3. ])

    Note that 3 = 6 / 2!, and that the constants are given in the order of
    integrations. Constant of the highest-order polynomial term comes first:

    >>> np.polyder(P, 2)(0)
    6.0
    >>> np.polyder(P, 1)(0)
    5.0
    >>> P(0)
    3.0

    rz0Order of integral must be positive (see polyder)Nr*z7k must be a scalar or a rank-1 array of length 1 or >m.rD)rC)rFr3r5rHrGrr/r�
isinstancerr:�concatenate�__truediv__�aranger)rI�mrC�truepoly�y�valr'r'r(r�s,C

(cCs~t|�}|dkrtd��t|t�}t�|�}t|�d}|dd�t�|dd�}|dkr`|}nt||d�}|rzt|�}|S)ab
    Return the derivative of the specified order of a polynomial.

    Parameters
    ----------
    p : poly1d or sequence
        Polynomial to differentiate.
        A sequence is interpreted as polynomial coefficients, see `poly1d`.
    m : int, optional
        Order of differentiation (default: 1)

    Returns
    -------
    der : poly1d
        A new polynomial representing the derivative.

    See Also
    --------
    polyint : Anti-derivative of a polynomial.
    poly1d : Class for one-dimensional polynomials.

    Examples
    --------
    The derivative of the polynomial :math:`x^3 + x^2 + x^1 + 1` is:

    >>> p = np.poly1d([1,1,1,1])
    >>> p2 = np.polyder(p)
    >>> p2
    poly1d([3, 2, 1])

    which evaluates to:

    >>> p2(2.)
    17.0

    We can verify this, approximating the derivative with
    ``(f(x + h) - f(x))/h``:

    >>> (p(2. + 0.001) - p(2.)) / 0.001
    17.007000999997857

    The fourth-order derivative of a 3rd-order polynomial is zero:

    >>> np.polyder(p, 2)
    poly1d([6, 2])
    >>> np.polyder(p, 3)
    poly1d([6])
    >>> np.polyder(p, 4)
    poly1d([ 0.])

    rz2Order of derivative must be positive (see polyint)r*NrD)	rFr3rLrr5r:r/rOr)rIrPrQ�nrRrSr'r'r(rJs4

FcCsTt|�d}t�|�d}t�|�d}|dkr8td��|jdkrJtd��|jdkr\td��|jdksp|jdkrxtd��|jd|jdkr�td	��|d
kr�t|�t	|j
�j}t||�}|}	|d
k	�rHt�|�d}|jdkr�td��|jd|jdk�rtd��||d
d
�tj
f9}|	jdk�r@|	|d
d
�tj
f9}	n|	|9}	t�||jdd
��}
||
}t||	|�\}}}
}|j|
j}|
|k�r�|�s�d}tj|tdd�|�r�|||
||fS|�rLtt|j|��}|t�|
|
�}t|�|dk�r�td��|t|�|d}|jdk�r*|||fS||d
d
�d
d
�tj
f|fSn|Sd
S)a�
    Least squares polynomial fit.

    Fit a polynomial ``p(x) = p[0] * x**deg + ... + p[deg]`` of degree `deg`
    to points `(x, y)`. Returns a vector of coefficients `p` that minimises
    the squared error.

    Parameters
    ----------
    x : array_like, shape (M,)
        x-coordinates of the M sample points ``(x[i], y[i])``.
    y : array_like, shape (M,) or (M, K)
        y-coordinates of the sample points. Several data sets of sample
        points sharing the same x-coordinates can be fitted at once by
        passing in a 2D-array that contains one dataset per column.
    deg : int
        Degree of the fitting polynomial
    rcond : float, optional
        Relative condition number of the fit. Singular values smaller than
        this relative to the largest singular value will be ignored. The
        default value is len(x)*eps, where eps is the relative precision of
        the float type, about 2e-16 in most cases.
    full : bool, optional
        Switch determining nature of return value. When it is False (the
        default) just the coefficients are returned, when True diagnostic
        information from the singular value decomposition is also returned.
    w : array_like, shape (M,), optional
        Weights to apply to the y-coordinates of the sample points. For
        gaussian uncertainties, use 1/sigma (not 1/sigma**2).
    cov : bool, optional
        Return the estimate and the covariance matrix of the estimate
        If full is True, then cov is not returned.

    Returns
    -------
    p : ndarray, shape (deg + 1,) or (deg + 1, K)
        Polynomial coefficients, highest power first.  If `y` was 2-D, the
        coefficients for `k`-th data set are in ``p[:,k]``.

    residuals, rank, singular_values, rcond
        Present only if `full` = True.  Residuals of the least-squares fit,
        the effective rank of the scaled Vandermonde coefficient matrix,
        its singular values, and the specified value of `rcond`. For more
        details, see `linalg.lstsq`.

    V : ndarray, shape (M,M) or (M,M,K)
        Present only if `full` = False and `cov`=True.  The covariance
        matrix of the polynomial coefficient estimates.  The diagonal of
        this matrix are the variance estimates for each coefficient.  If y
        is a 2-D array, then the covariance matrix for the `k`-th data set
        are in ``V[:,:,k]``


    Warns
    -----
    RankWarning
        The rank of the coefficient matrix in the least-squares fit is
        deficient. The warning is only raised if `full` = False.

        The warnings can be turned off by

        >>> import warnings
        >>> warnings.simplefilter('ignore', np.RankWarning)

    See Also
    --------
    polyval : Compute polynomial values.
    linalg.lstsq : Computes a least-squares fit.
    scipy.interpolate.UnivariateSpline : Computes spline fits.

    Notes
    -----
    The solution minimizes the squared error

    .. math ::
        E = \sum_{j=0}^k |p(x_j) - y_j|^2

    in the equations::

        x[0]**n * p[0] + ... + x[0] * p[n-1] + p[n] = y[0]
        x[1]**n * p[0] + ... + x[1] * p[n-1] + p[n] = y[1]
        ...
        x[k]**n * p[0] + ... + x[k] * p[n-1] + p[n] = y[k]

    The coefficient matrix of the coefficients `p` is a Vandermonde matrix.

    `polyfit` issues a `RankWarning` when the least-squares fit is badly
    conditioned. This implies that the best fit is not well-defined due
    to numerical error. The results may be improved by lowering the polynomial
    degree or by replacing `x` by `x` - `x`.mean(). The `rcond` parameter
    can also be set to a value smaller than its default, but the resulting
    fit may be spurious: including contributions from the small singular
    values can add numerical noise to the result.

    Note that fitting polynomial coefficients is inherently badly conditioned
    when the degree of the polynomial is large or the interval of sample points
    is badly centered. The quality of the fit should always be checked in these
    cases. When polynomial fits are not satisfactory, splines may be a good
    alternative.

    References
    ----------
    .. [1] Wikipedia, "Curve fitting",
           http://en.wikipedia.org/wiki/Curve_fitting
    .. [2] Wikipedia, "Polynomial interpolation",
           http://en.wikipedia.org/wiki/Polynomial_interpolation

    Examples
    --------
    >>> x = np.array([0.0, 1.0, 2.0, 3.0,  4.0,  5.0])
    >>> y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0])
    >>> z = np.polyfit(x, y, 3)
    >>> z
    array([ 0.08703704, -0.81349206,  1.69312169, -0.03968254])

    It is convenient to use `poly1d` objects for dealing with polynomials:

    >>> p = np.poly1d(z)
    >>> p(0.5)
    0.6143849206349179
    >>> p(3.5)
    -0.34732142857143039
    >>> p(10)
    22.579365079365115

    High-order polynomials may oscillate wildly:

    >>> p30 = np.poly1d(np.polyfit(x, y, 30))
    /... RankWarning: Polyfit may be poorly conditioned...
    >>> p30(4)
    -0.80000000000000204
    >>> p30(5)
    -0.99999999999999445
    >>> p30(4.5)
    -0.10547061179440398

    Illustration:

    >>> import matplotlib.pyplot as plt
    >>> xp = np.linspace(-2, 6, 100)
    >>> _ = plt.plot(x, y, '.', xp, p(xp), '-', xp, p30(xp), '--')
    >>> plt.ylim(-2,2)
    (-2, 2)
    >>> plt.show()

    r*grzexpected deg >= 0zexpected 1D vector for xzexpected non-empty vector for xr)zexpected 1D or 2D array for yz$expected x and y to have same lengthNz expected a 1-d array for weightsz(expected w and y to have the same length)Zaxisz!Polyfit may be poorly conditioned)�
stacklevelz[the number of data points must exceed order + 2 for Bayesian estimate the covariance matrixg@)rFr5r:r3rE�	TypeError�sizer.r/rr+�epsrZnewaxis�sqrt�sumr!�T�warnings�warnrr"rZouter)�xrR�degZrcondr,�wZcov�order�lhs�rhs�scale�cZresidsZrank�s�msgZVbaseZfacr'r'r(r�s^




"cCsXt�|�}t|t�rd}nt�|�}t�|�}x$tt|��D]}||||}q<W|S)aH
    Evaluate a polynomial at specific values.

    If `p` is of length N, this function returns the value:

        ``p[0]*x**(N-1) + p[1]*x**(N-2) + ... + p[N-2]*x + p[N-1]``

    If `x` is a sequence, then `p(x)` is returned for each element of `x`.
    If `x` is another polynomial then the composite polynomial `p(x(t))`
    is returned.

    Parameters
    ----------
    p : array_like or poly1d object
       1D array of polynomial coefficients (including coefficients equal
       to zero) from highest degree to the constant term, or an
       instance of poly1d.
    x : array_like or poly1d object
       A number, an array of numbers, or an instance of poly1d, at
       which to evaluate `p`.

    Returns
    -------
    values : ndarray or poly1d
       If `x` is a poly1d instance, the result is the composition of the two
       polynomials, i.e., `x` is "substituted" in `p` and the simplified
       result is returned. In addition, the type of `x` - array_like or
       poly1d - governs the type of the output: `x` array_like => `values`
       array_like, `x` a poly1d object => `values` is also.

    See Also
    --------
    poly1d: A polynomial class.

    Notes
    -----
    Horner's scheme [1]_ is used to evaluate the polynomial. Even so,
    for polynomials of high degree the values may be inaccurate due to
    rounding errors. Use carefully.

    References
    ----------
    .. [1] I. N. Bronshtein, K. A. Semendyayev, and K. A. Hirsch (Eng.
       trans. Ed.), *Handbook of Mathematics*, New York, Van Nostrand
       Reinhold Co., 1985, pg. 720.

    Examples
    --------
    >>> np.polyval([3,0,1], 5)  # 3 * 5**2 + 0 * 5**1 + 1
    76
    >>> np.polyval([3,0,1], np.poly1d(5))
    poly1d([ 76.])
    >>> np.polyval(np.poly1d([3,0,1]), 5)
    76
    >>> np.polyval(np.poly1d([3,0,1]), np.poly1d(5))
    poly1d([ 76.])

    r)r5r:rLrZ
zeros_liker4r/)rIr^rR�ir'r'r(r
fs;



cCs�t|t�pt|t�}t|�}t|�}t|�t|�}|dkrF||}nN|dkrpt�||j�}t�||f�|}n$t�t|�|j�}|t�||f�}|r�t|�}|S)a6
    Find the sum of two polynomials.

    Returns the polynomial resulting from the sum of two input polynomials.
    Each input must be either a poly1d object or a 1D sequence of polynomial
    coefficients, from highest to lowest degree.

    Parameters
    ----------
    a1, a2 : array_like or poly1d object
        Input polynomials.

    Returns
    -------
    out : ndarray or poly1d object
        The sum of the inputs. If either input is a poly1d object, then the
        output is also a poly1d object. Otherwise, it is a 1D array of
        polynomial coefficients from highest to lowest degree.

    See Also
    --------
    poly1d : A one-dimensional polynomial class.
    poly, polyadd, polyder, polydiv, polyfit, polyint, polysub, polyval

    Examples
    --------
    >>> np.polyadd([1, 2], [9, 5, 4])
    array([9, 6, 6])

    Using poly1d objects:

    >>> p1 = np.poly1d([1, 2])
    >>> p2 = np.poly1d([9, 5, 4])
    >>> print(p1)
    1 x + 2
    >>> print(p2)
       2
    9 x + 5 x + 4
    >>> print(np.polyadd(p1, p2))
       2
    9 x + 6 x + 6

    r)	rLrrr/r5rHr+rMr)�a1�a2rQ�diffrS�zrr'r'r(r	�s,
cCs�t|t�pt|t�}t|�}t|�}t|�t|�}|dkrF||}nN|dkrpt�||j�}t�||f�|}n$t�t|�|j�}|t�||f�}|r�t|�}|S)a�
    Difference (subtraction) of two polynomials.

    Given two polynomials `a1` and `a2`, returns ``a1 - a2``.
    `a1` and `a2` can be either array_like sequences of the polynomials'
    coefficients (including coefficients equal to zero), or `poly1d` objects.

    Parameters
    ----------
    a1, a2 : array_like or poly1d
        Minuend and subtrahend polynomials, respectively.

    Returns
    -------
    out : ndarray or poly1d
        Array or `poly1d` object of the difference polynomial's coefficients.

    See Also
    --------
    polyval, polydiv, polymul, polyadd

    Examples
    --------
    .. math:: (2 x^2 + 10 x - 2) - (3 x^2 + 10 x -4) = (-x^2 + 2)

    >>> np.polysub([2, 10, -2], [3, 10, -4])
    array([-1,  0,  2])

    r)	rLrrr/r5rHr+rMr)rirjrQrkrSrlr'r'r(r
�s
cCsBt|t�pt|t�}t|�t|�}}t�||�}|r>t|�}|S)a'
    Find the product of two polynomials.

    Finds the polynomial resulting from the multiplication of the two input
    polynomials. Each input must be either a poly1d object or a 1D sequence
    of polynomial coefficients, from highest to lowest degree.

    Parameters
    ----------
    a1, a2 : array_like or poly1d object
        Input polynomials.

    Returns
    -------
    out : ndarray or poly1d object
        The polynomial resulting from the multiplication of the inputs. If
        either inputs is a poly1d object, then the output is also a poly1d
        object. Otherwise, it is a 1D array of polynomial coefficients from
        highest to lowest degree.

    See Also
    --------
    poly1d : A one-dimensional polynomial class.
    poly, polyadd, polyder, polydiv, polyfit, polyint, polysub,
    polyval
    convolve : Array convolution. Same output as polymul, but has parameter
               for overlap mode.

    Examples
    --------
    >>> np.polymul([1, 2, 3], [9, 5, 1])
    array([ 9, 23, 38, 17,  3])

    Using poly1d objects:

    >>> p1 = np.poly1d([1, 2, 3])
    >>> p2 = np.poly1d([9, 5, 1])
    >>> print(p1)
       2
    1 x + 2 x + 3
    >>> print(p2)
       2
    9 x + 5 x + 1
    >>> print(np.polymul(p1, p2))
       4      3      2
    9 x + 23 x + 38 x + 17 x + 3

    )rLrr5r6)rirjrQrSr'r'r(rs1cCs,t|t�pt|t�}t|�d}t|�d}|d|d}t|�d}t|�d}d|d}t�t||dd�f|j�}|��}xNt	d||d�D]8}	|||	}
|
||	<||	|	|d�|
|8<q�Wx6tj
|dddd��r|jddk�r|dd�}q�W|�r$t|�t|�fS||fS)	a�
    Returns the quotient and remainder of polynomial division.

    The input arrays are the coefficients (including any coefficients
    equal to zero) of the "numerator" (dividend) and "denominator"
    (divisor) polynomials, respectively.

    Parameters
    ----------
    u : array_like or poly1d
        Dividend polynomial's coefficients.

    v : array_like or poly1d
        Divisor polynomial's coefficients.

    Returns
    -------
    q : ndarray
        Coefficients, including those equal to zero, of the quotient.
    r : ndarray
        Coefficients, including those equal to zero, of the remainder.

    See Also
    --------
    poly, polyadd, polyder, polydiv, polyfit, polyint, polymul, polysub,
    polyval

    Notes
    -----
    Both `u` and `v` must be 0-d or 1-d (ndim = 0 or 1), but `u.ndim` need
    not equal `v.ndim`. In other words, all four possible combinations -
    ``u.ndim = v.ndim = 0``, ``u.ndim = v.ndim = 1``,
    ``u.ndim = 1, v.ndim = 0``, and ``u.ndim = 0, v.ndim = 1`` - work.

    Examples
    --------
    .. math:: \frac{3x^2 + 5x + 2}{2x + 1} = 1.5x + 1.75, remainder 0.25

    >>> x = np.array([3.0, 5.0, 2.0])
    >>> y = np.array([2.0, 1.0])
    >>> np.polydiv(x, y)
    (array([ 1.5 ,  1.75]), array([ 0.25]))

    grr*g�?g�+����=)ZrtolrDN)rLrrr/r5rH�maxr+r?r4Zallcloser.)�u�vrQr`rPrTrd�q�rrC�dr'r'r(rNs$-$(z[*][*]([0-9]*)�FcCsd}d}d}d}x�t�||�}|dkr(P|��}|��d}|||d�}	|d}|	dt|�d}
dt|	�d|}t|�t|
�|ks�t|�t|�|kr�||d|d7}|}|
}q||	dt|�d7}|dt|	�d|7}qW||d|7}|||d�S)Nr�� r*�
z
 )�	_poly_mat�search�span�groupsr/)�astr�wraprTZline1Zline2�output�matry�powerZpartstrZtoadd2Ztoadd1r'r'r(�_raise_power�s.r�c@sPeZdZdZdZedd��Zejdd��Zedd��Zedd	��Z	ed
d��Z
edd
��Zejdd
��Ze
ZeZ
ZZe	ZdBdd�ZdCdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Z e Z!d0d1�Z"e"Z#d2d3�Z$d4d5�Z%d6d7�Z&d8d9�Z'd:d;�Z(dDd>d?�Z)dEd@dA�Z*dS)Fra8

    A one-dimensional polynomial class.

    A convenience class, used to encapsulate "natural" operations on
    polynomials so that said operations may take on their customary
    form in code (see Examples).

    Parameters
    ----------
    c_or_r : array_like
        The polynomial's coefficients, in decreasing powers, or if
        the value of the second parameter is True, the polynomial's
        roots (values where the polynomial evaluates to 0).  For example,
        ``poly1d([1, 2, 3])`` returns an object that represents
        :math:`x^2 + 2x + 3`, whereas ``poly1d([1, 2, 3], True)`` returns
        one that represents :math:`(x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x -6`.
    r : bool, optional
        If True, `c_or_r` specifies the polynomial's roots; the default
        is False.
    variable : str, optional
        Changes the variable used when printing `p` from `x` to `variable`
        (see Examples).

    Examples
    --------
    Construct the polynomial :math:`x^2 + 2x + 3`:

    >>> p = np.poly1d([1, 2, 3])
    >>> print(np.poly1d(p))
       2
    1 x + 2 x + 3

    Evaluate the polynomial at :math:`x = 0.5`:

    >>> p(0.5)
    4.25

    Find the roots:

    >>> p.r
    array([-1.+1.41421356j, -1.-1.41421356j])
    >>> p(p.r)
    array([ -4.44089210e-16+0.j,  -4.44089210e-16+0.j])

    These numbers in the previous line represent (0, 0) to machine precision

    Show the coefficients:

    >>> p.c
    array([1, 2, 3])

    Display the order (the leading zero-coefficients are removed):

    >>> p.order
    2

    Show the coefficient of the k-th power in the polynomial
    (which is equivalent to ``p.c[-(i+1)]``):

    >>> p[1]
    2

    Polynomials can be added, subtracted, multiplied, and divided
    (returns quotient and remainder):

    >>> p * p
    poly1d([ 1,  4, 10, 12,  9])

    >>> (p**3 + 4) / p
    (poly1d([  1.,   4.,  10.,  12.,   9.]), poly1d([ 4.]))

    ``asarray(p)`` gives the coefficient array, so polynomials can be
    used in all functions that accept arrays:

    >>> p**2 # square of polynomial
    poly1d([ 1,  4, 10, 12,  9])

    >>> np.square(p) # square of individual coefficients
    array([1, 4, 9])

    The variable used in the string representation of `p` can be modified,
    using the `variable` parameter:

    >>> p = np.poly1d([1,2,3], variable='z')
    >>> print(p)
       2
    1 z + 2 z + 3

    Construct a polynomial from its roots:

    >>> np.poly1d([1, 2], True)
    poly1d([ 1, -3,  2])

    This is the same polynomial as obtained by:

    >>> np.poly1d([1, -1]) * np.poly1d([1, -2])
    poly1d([ 1, -3,  2])

    NcCs|jS)z The polynomial coefficients )�_coeffs)�selfr'r'r(�coeffssz
poly1d.coeffscCs||jk	rtd��dS)NzCannot set attribute)r��AttributeError)r��valuer'r'r(r�s
cCs|jS)z% The name of the polynomial variable )�	_variable)r�r'r'r(�variableszpoly1d.variablecCst|j�dS)z' The order or degree of the polynomial r*)r/r�)r�r'r'r(ra"szpoly1d.ordercCs
t|j�S)z1 The roots of the polynomial, where self(x) == 0 )rr�)r�r'r'r(r'szpoly1d.rootscCs
|jdS)Nr�)�__dict__)r�r'r'r(r�.szpoly1d._coeffscCs||jd<dS)Nr�)r�)r�r�r'r'r(r�1sFcCs�t|t�rb|j|_|j|_t|j�t|j�rPd}tj|tdd�|j�	|j�|dk	r^||_dS|rnt
|�}t|�}|jdkr�t
d��t|dd�}t|�dkr�t�d	g�}||_|dkr�d
}||_dS)NzbIn the future extra properties will not be copied across when constructing one poly1d from anotherr))rUr*zPolynomial must be 1d only.�f)Ztrimrgr^)rLrr�r��setr�r\r]�
FutureWarning�updaterrrEr3rr/r5r)r�Zc_or_rrqr�rgr'r'r(�__init__:s,

zpoly1d.__init__cCs"|rt�|j|�St�|j�SdS)N)r5r:r�)r��tr'r'r(�	__array__Uszpoly1d.__array__cCst|j�}|dd�}d|S)N�rDz
poly1d(%s))�reprr�)r��valsr'r'r(�__repr__[s
zpoly1d.__repr__cCs|jS)N)ra)r�r'r'r(�__len__`szpoly1d.__len__c
Cs�d}|j}|jtj�|jdk�}t|�d}dd�}�xltt|��D�]Z}t||�sj|t||��}nJt||�dkr�d|t	||��}n$d|t||��|t	||��f}||}|dkr�|dkr�d|f}	n|dkr�d}	nd	}	nn|dk�r$|dk�rd	}	n|d
k�r|}	nd||f}	n6|dk�r4d	}	n&|d
k�rLd||f}	nd
|||f}	|dk�r�|	d	k�r�|	�
d��r�d||	dd�f}nd||	f}qF|	}qFWt|�S)N�0rr*cSs"d|}|�d�r|dd�}|S)Nz%.4gz.0000���)�endswith)rprfr'r'r(�	fmt_floatks
z!poly1d.__str__.<locals>.fmt_floatz%sjz
(%s + %sj)z%srt�bz%s %sz%s**%dz	%s %s**%d�-z%s - %sz%s + %s)r�r�r5�
logical_or�
accumulater/r4rrr�
startswithr�)
r�Zthestr�varr�rJr�rCZcoefstrr�newstrr'r'r(�__str__csJ






zpoly1d.__str__cCst|j|�S)N)r
r�)r�rSr'r'r(�__call__�szpoly1d.__call__cCst|j�S)N)rr�)r�r'r'r(�__neg__�szpoly1d.__neg__cCs|S)Nr')r�r'r'r(�__pos__�szpoly1d.__pos__cCs4t|�rt|j|�St|�}tt|j|j��SdS)N)rrr�r)r��otherr'r'r(�__mul__�szpoly1d.__mul__cCs4t|�rt||j�St|�}tt|j|j��SdS)N)rrr�r)r�r�r'r'r(�__rmul__�szpoly1d.__rmul__cCst|�}tt|j|j��S)N)rr	r�)r�r�r'r'r(�__add__�szpoly1d.__add__cCst|�}tt|j|j��S)N)rr	r�)r�r�r'r'r(�__radd__�szpoly1d.__radd__cCsPt|�rt|�|ks|dkr$td��dg}xt|�D]}t|j|�}q4Wt|�S)Nrz$Power to non-negative integers only.r*)rrFr3r4rr�r)r�rS�res�_r'r'r(�__pow__�szpoly1d.__pow__cCst|�}tt|j|j��S)N)rr
r�)r�r�r'r'r(�__sub__�szpoly1d.__sub__cCst|�}tt|j|j��S)N)rr
r�)r�r�r'r'r(�__rsub__�szpoly1d.__rsub__cCs,t|�rt|j|�St|�}t||�SdS)N)rrr�r)r�r�r'r'r(�__div__�szpoly1d.__div__cCs,t|�rt||j�St|�}t||�SdS)N)rrr�r)r�r�r'r'r(�__rdiv__�szpoly1d.__rdiv__cCs2t|t�stS|jj|jjkr"dS|j|jk��S)NF)rLr�NotImplementedr�r.r<)r�r�r'r'r(�__eq__�s

z
poly1d.__eq__cCst|t�stS|�|�S)N)rLrr�r�)r�r�r'r'r(�__ne__�s
z
poly1d.__ne__cCs.|j|}||jkrdS|dkr$dS|j|S)Nr)rar�)r�rS�indr'r'r(�__getitem__�s

zpoly1d.__getitem__cCs^|j|}|dkrtd��||jkrPt�||j|jj�}t�||jf�|_d}||j|<dS)Nrz!Does not support negative powers.)rar3r5rHr�r+rMr�)r��keyrSr�rlr'r'r(�__setitem__�s


zpoly1d.__setitem__cCs
t|j�S)N)�iterr�)r�r'r'r(�__iter__�szpoly1d.__iter__r*rcCstt|j||d��S)z�
        Return an antiderivative (indefinite integral) of this polynomial.

        Refer to `polyint` for full documentation.

        See Also
        --------
        polyint : equivalent function

        )rPrC)rrr�)r�rPrCr'r'r(�integszpoly1d.integcCstt|j|d��S)z�
        Return a derivative of this polynomial.

        Refer to `polyder` for full documentation.

        See Also
        --------
        polyder : equivalent function

        )rP)rrr�)r�rPr'r'r(�deriv
szpoly1d.deriv)FN)N)r*r)r*)+r#r$r%r&�__hash__�propertyr��setterr�rarr�rqreZcoefZcoefficients�or�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rNr��__rtruediv__r�r�r�r�r�r�r�r'r'r'r(r�sLc

9

�always)r*N)r*)NFNF)rs)5r&�
__future__rrr�__all__�rer\Znumpy.core.numeric�core�numericr5Z
numpy.corerrrrrrrrZnumpy.lib.twodim_baserrZnumpy.lib.function_baserZnumpy.lib.type_checkrrrrZnumpy.linalgr r!r"�UserWarningrrrrrrr
r	r
rr�compilerwr�r0r�simplefilterr'r'r'r(�<module>s<

(
yT
]
D
YE</8A

s

Youez - 2016 - github.com/yon3zu
LinuXploit