ó 2ÄÈ[c@`s^dZddlmZmZmZddlZddlZddlj Z ddl m Z ddl mZddlmZdd d d d d ddddddddddddddddddd d!d"d#d$d%d&gZejZd'„Zd(„Zejd)dgƒZejdgƒZejdgƒZejddEgƒZd+„Zd,„Zd-„Zd.„Zd/„Z d0„Z!d1„Z"d2d3„Z#dddd4„Z$dgdddd5„Z%e&d6„Z'd7„Z(d8„Z)d9„Z*d:„Z+d;„Z,d<„Z-d=„Z.de0dd>„Z1d?„Z2d@„Z3dA„Z4dB„Z5dC„Z6defdD„ƒYZ7dS(Fsæ Objects for dealing with Hermite series. This module provides a number of objects (mostly functions) useful for dealing with Hermite series, including a `Hermite` class that encapsulates the usual arithmetic operations. (General information on how this module represents and works with such polynomials is in the docstring for its "parent" sub-package, `numpy.polynomial`). Constants --------- - `hermdomain` -- Hermite series default domain, [-1,1]. - `hermzero` -- Hermite series that evaluates identically to 0. - `hermone` -- Hermite series that evaluates identically to 1. - `hermx` -- Hermite series for the identity map, ``f(x) = x``. Arithmetic ---------- - `hermmulx` -- multiply a Hermite series in ``P_i(x)`` by ``x``. - `hermadd` -- add two Hermite series. - `hermsub` -- subtract one Hermite series from another. - `hermmul` -- multiply two Hermite series. - `hermdiv` -- divide one Hermite series by another. - `hermval` -- evaluate a Hermite series at given points. - `hermval2d` -- evaluate a 2D Hermite series at given points. - `hermval3d` -- evaluate a 3D Hermite series at given points. - `hermgrid2d` -- evaluate a 2D Hermite series on a Cartesian product. - `hermgrid3d` -- evaluate a 3D Hermite series on a Cartesian product. Calculus -------- - `hermder` -- differentiate a Hermite series. - `hermint` -- integrate a Hermite series. Misc Functions -------------- - `hermfromroots` -- create a Hermite series with specified roots. - `hermroots` -- find the roots of a Hermite series. - `hermvander` -- Vandermonde-like matrix for Hermite polynomials. - `hermvander2d` -- Vandermonde-like matrix for 2D power series. - `hermvander3d` -- Vandermonde-like matrix for 3D power series. - `hermgauss` -- Gauss-Hermite quadrature, points and weights. - `hermweight` -- Hermite weight function. - `hermcompanion` -- symmetrized companion matrix in Hermite form. - `hermfit` -- least-squares fit returning a Hermite series. - `hermtrim` -- trim leading coefficients from a Hermite series. - `hermline` -- Hermite series of given straight line. - `herm2poly` -- convert a Hermite series to a polynomial. - `poly2herm` -- convert a polynomial to a Hermite series. Classes ------- - `Hermite` -- A Hermite series class. See also -------- `numpy.polynomial` i(tdivisiontabsolute_importtprint_functionN(tnormalize_axis_indexi(t polyutils(t ABCPolyBasethermzerothermonethermxt hermdomainthermlinethermaddthermsubthermmulxthermmulthermdivthermpowthermvalthermderthermintt herm2polyt poly2hermt hermfromrootst hermvanderthermfitthermtrimt hermrootstHermitet hermval2dt hermval3dt hermgrid2dt hermgrid3dt hermvander2dt hermvander3dt hermcompaniont hermgausst hermweightcC`setj|gƒ\}t|ƒd}d}x3t|ddƒD]}tt|ƒ||ƒ}q>W|S(sŒ poly2herm(pol) Convert a polynomial to a Hermite series. Convert an array representing the coefficients of a polynomial (relative to the "standard" basis) ordered from lowest degree to highest, to an array of the coefficients of the equivalent Hermite series, ordered from lowest to highest degree. Parameters ---------- pol : array_like 1-D array containing the polynomial coefficients Returns ------- c : ndarray 1-D array containing the coefficients of the equivalent Hermite series. See Also -------- herm2poly Notes ----- The easy way to do conversions between polynomial basis sets is to use the convert method of a class instance. Examples -------- >>> from numpy.polynomial.hermite import poly2herm >>> poly2herm(np.arange(4)) array([ 1. , 2.75 , 0.5 , 0.375]) iiiÿÿÿÿ(tput as_seriestlentrangeR R (tpoltdegtresti((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRQs &c C`sÿddlm}m}m}tj|gƒ\}t|ƒ}|dkrM|S|dkrm|dcd9<|S|d}|d}x`t|dddƒD]H}|}|||d|d|dƒ}||||ƒdƒ}q˜W||||ƒdƒSdS(s  Convert a Hermite series to a polynomial. Convert an array representing the coefficients of a Hermite series, ordered from lowest degree to highest, to an array of the coefficients of the equivalent polynomial (relative to the "standard" basis) ordered from lowest to highest degree. Parameters ---------- c : array_like 1-D array containing the Hermite series coefficients, ordered from lowest order term to highest. Returns ------- pol : ndarray 1-D array containing the coefficients of the equivalent polynomial (relative to the "standard" basis) ordered from lowest order term to highest. See Also -------- poly2herm Notes ----- The easy way to do conversions between polynomial basis sets is to use the convert method of a class instance. Examples -------- >>> from numpy.polynomial.hermite import herm2poly >>> herm2poly([ 1. , 2.75 , 0.5 , 0.375]) array([ 0., 1., 2., 3.]) i(tpolyaddtpolysubtpolymulxiiþÿÿÿiÿÿÿÿN(t polynomialR-R.R/R%R&R'R(( tcR-R.R/tntc0tc1R,ttmp((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRs&     #iÿÿÿÿicC`s7|dkr#tj||dgƒStj|gƒSdS(s  Hermite series whose graph is a straight line. Parameters ---------- off, scl : scalars The specified line is given by ``off + scl*x``. Returns ------- y : ndarray This module's representation of the Hermite series for ``off + scl*x``. See Also -------- polyline, chebline Examples -------- >>> from numpy.polynomial.hermite import hermline, hermval >>> hermval(0,hermline(3, 2)) 3.0 >>> hermval(1,hermline(3, 2)) 5.0 iiN(tnptarray(tofftscl((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR Ês cC`s t|ƒdkrtjdƒStj|gdtƒ\}|jƒg|D]}t| dƒ^qK}t|ƒ}x‰|dkrþt|dƒ\}}gt |ƒD]!}t |||||ƒ^q¤}|rït |d|dƒ|d>> from numpy.polynomial.hermite import hermfromroots, hermval >>> coef = hermfromroots((-1, 0, 1)) >>> hermval((-1, 0, 1), coef) array([ 0., 0., 0.]) >>> coef = hermfromroots((-1j, 1j)) >>> hermval((-1j, 1j), coef) array([ 0.+0.j, 0.+0.j]) iittrimiiÿÿÿÿN( R'R6tonesR%R&tFalsetsortR tdivmodR(R(trootstrtpR2tmR,R5((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRîs2  # 4 cC`sutj||gƒ\}}t|ƒt|ƒkrO||jc |7*|}n||jc |7*|}tj|ƒS(sÞ Add one Hermite series to another. Returns the sum of two Hermite series `c1` + `c2`. The arguments are sequences of coefficients ordered from lowest order term to highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``. Parameters ---------- c1, c2 : array_like 1-D arrays of Hermite series coefficients ordered from low to high. Returns ------- out : ndarray Array representing the Hermite series of their sum. See Also -------- hermsub, hermmul, hermdiv, hermpow Notes ----- Unlike multiplication, division, etc., the sum of two Hermite series is a Hermite series (without having to "reproject" the result onto the basis set) so addition, just like that of "standard" polynomials, is simply "component-wise." Examples -------- >>> from numpy.polynomial.hermite import hermadd >>> hermadd([1, 2, 3], [1, 2, 3, 4]) array([ 2., 4., 6., 4.]) (R%R&R'tsizettrimseq(R4tc2tret((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR 1s& cC`s|tj||gƒ\}}t|ƒt|ƒkrO||jc |8*|}n | }||jc |7*|}tj|ƒS(sî Subtract one Hermite series from another. Returns the difference of two Hermite series `c1` - `c2`. The sequences of coefficients are from lowest order term to highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``. Parameters ---------- c1, c2 : array_like 1-D arrays of Hermite series coefficients ordered from low to high. Returns ------- out : ndarray Of Hermite series coefficients representing their difference. See Also -------- hermadd, hermmul, hermdiv, hermpow Notes ----- Unlike multiplication, division, etc., the difference of two Hermite series is a Hermite series (without having to "reproject" the result onto the basis set) so subtraction, just like that of "standard" polynomials, is simply "component-wise." Examples -------- >>> from numpy.polynomial.hermite import hermsub >>> hermsub([1, 2, 3, 4], [1, 2, 3]) array([ 0., 0., 0., 4.]) (R%R&R'RCRD(R4RERF((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR as& cC`s×tj|gƒ\}t|ƒdkr;|ddkr;|Stjt|ƒdd|jƒ}|dd|d<|dd|d>> from numpy.polynomial.hermite import hermmulx >>> hermmulx([1, 2, 3]) array([ 2. , 6.5, 1. , 1.5]) iitdtypei(R%R&R'R6temptyRGR((R1tprdR,((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR ’s#"" cC`sXtj||gƒ\}}t|ƒt|ƒkrB|}|}n |}|}t|ƒdkrw|d|}d}nÊt|ƒdkr¨|d|}|d|}n™t|ƒ}|d|}|d|}xntdt|ƒdƒD]S}|}|d}t|| ||d|dƒ}t|t|ƒdƒ}qêWt|t|ƒdƒS(sH Multiply one Hermite series by another. Returns the product of two Hermite series `c1` * `c2`. The arguments are sequences of coefficients, from lowest order "term" to highest, e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``. Parameters ---------- c1, c2 : array_like 1-D arrays of Hermite series coefficients ordered from low to high. Returns ------- out : ndarray Of Hermite series coefficients representing their product. See Also -------- hermadd, hermsub, hermdiv, hermpow Notes ----- In general, the (polynomial) product of two C-series results in terms that are not in the Hermite polynomial basis set. Thus, to express the product as a Hermite series, it is necessary to "reproject" the product onto said basis set, which may produce "unintuitive" (but correct) results; see Examples section below. Examples -------- >>> from numpy.polynomial.hermite import hermmul >>> hermmul([1, 2, 3], [0, 1, 2]) array([ 52., 29., 52., 7., 6.]) iiiiþÿÿÿiÿÿÿÿi(R%R&R'R(R R R (R4RER1txsR3tndR,R5((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRÃs*'     $c C`s@tj||gƒ\}}|ddkr7tƒ‚nt|ƒ}t|ƒ}||krm|d d|fS|dkr“||d|d dfStj||dd|jƒ}|}xmt||ddƒD]U}tdg|dg|ƒ}|d|d}|d ||d }|||>> from numpy.polynomial.hermite import hermdiv >>> hermdiv([ 52., 29., 52., 7., 6.], [0, 1, 2]) (array([ 1., 2., 3.]), array([ 0.])) >>> hermdiv([ 54., 31., 52., 7., 6.], [0, 1, 2]) (array([ 1., 2., 3.]), array([ 2., 2.])) >>> hermdiv([ 53., 30., 52., 7., 6.], [0, 1, 2]) (array([ 1., 2., 3.]), array([ 1., 1.])) iÿÿÿÿiiRGN( R%R&tZeroDivisionErrorR'R6RHRGR(RRD( R4REtlc1tlc2tquotremR,RAtq((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRs".      icC`sßtj|gƒ\}t|ƒ}||ks9|dkrHtdƒ‚n“|dk ro||krotdƒ‚nl|dkr”tjdgd|jƒS|dkr¤|S|}x*td|dƒD]}t ||ƒ}q¾W|SdS(svRaise a Hermite series to a power. Returns the Hermite series `c` raised to the power `pow`. The argument `c` is a sequence of coefficients ordered from low to high. i.e., [1,2,3] is the series ``P_0 + 2*P_1 + 3*P_2.`` Parameters ---------- c : array_like 1-D array of Hermite series coefficients ordered from low to high. pow : integer Power to which the series will be raised maxpower : integer, optional Maximum power allowed. This is mainly to limit growth of the series to unmanageable size. Default is 16 Returns ------- coef : ndarray Hermite series of power. See Also -------- hermadd, hermsub, hermmul, hermdiv Examples -------- >>> from numpy.polynomial.hermite import hermpow >>> hermpow([1, 2, 3], 2) array([ 81., 52., 82., 12., 9.]) is%Power must be a non-negative integer.sPower is too largeiRGiN( R%R&tintt ValueErrortNoneR6R7RGR(R(R1tpowtmaxpowertpowerRIR,((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRHs#   c C`sÅtj|ddddƒ}|jjdkrB|jtjƒ}ng||gD]}t|ƒ^qO\}}||krˆtdƒ‚n|dkr£tdƒ‚n||kr¾tdƒ‚nt||j ƒ}|dkrà|Stj ||dƒ}t |ƒ}||kr|d d}nŽx‹t |ƒD]}}|d}||9}tj |f|jdd |jƒ} x4t |dd ƒD] } d | || | | d>> from numpy.polynomial.hermite import hermder >>> hermder([ 1. , 0.5, 0.5, 0.5]) array([ 1., 2., 3.]) >>> hermder([-0.5, 1./2., 1./8., 1./12., 1./16.], m=2) array([ 1., 2., 3.]) tndminitcopys ?bBhHiIlLqQpPs'The order of derivation must be integeris,The order of derivation must be non-negativesThe axis must be integerRGiÿÿÿÿi(R6R7RGtchartastypetdoubleRRRSRtndimtmoveaxisR'R(RHtshape( R1RBR9taxistttcnttiaxisR2R,tdertj((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR~s47+        & c C`sÉtj|ddddƒ}|jjdkrB|jtjƒ}ntj|ƒs]|g}ng||gD]}t|ƒ^qj\}}||kr£tdƒ‚n|dkr¾tdƒ‚nt |ƒ|krßtdƒ‚ntj |ƒdkrtd ƒ‚ntj |ƒdkr'td ƒ‚n||krBtd ƒ‚nt ||j ƒ}|dkrd|Stj ||dƒ}t |ƒdg|t |ƒ}xt|ƒD]} t |ƒ} ||9}| dkrÿtj|ddkƒrÿ|dc|| 7 m``, ``np.ndim(lbnd) != 0``, or ``np.ndim(scl) != 0``. See Also -------- hermder Notes ----- Note that the result of each integration is *multiplied* by `scl`. Why is this important to note? Say one is making a linear change of variable :math:`u = ax + b` in an integral relative to `x`. Then :math:`dx = du/a`, so one will need to set `scl` equal to :math:`1/a` - perhaps not what one would have first thought. Also note that, in general, the result of integrating a C-series needs to be "reprojected" onto the C-series basis set. Thus, typically, the result of this function is "unintuitive," albeit correct; see Examples section below. Examples -------- >>> from numpy.polynomial.hermite import hermint >>> hermint([1,2,3]) # integrate once, value 0 at 0. array([ 1. , 0.5, 0.5, 0.5]) >>> hermint([1,2,3], m=2) # integrate twice, value & deriv 0 at 0 array([-0.5 , 0.5 , 0.125 , 0.08333333, 0.0625 ]) >>> hermint([1,2,3], k=1) # integrate once, value 1 at 0. array([ 2. , 0.5, 0.5, 0.5]) >>> hermint([1,2,3], lbnd=-1) # integrate once, value 0 at -1 array([-2. , 0.5, 0.5, 0.5]) >>> hermint([1,2,3], m=2, k=[1,2], lbnd=-1) array([ 1.66666667, -0.5 , 0.125 , 0.08333333, 0.0625 ]) RXiRYs ?bBhHiIlLqQpPs(The order of integration must be integeris-The order of integration must be non-negativesToo many integration constantsslbnd must be a scalar.sscl must be a scalar.sThe axis must be integerRGi(R6R7RGRZR[R\titerableRRRSR'R]RR^tlistR(tallRHR_R( R1RBtktlbndR9R`RaRbRcR,R2R5Re((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRÕsJS +    !  %*"! c C`s‚tj|ddddƒ}|jjdkrB|jtjƒ}nt|ttfƒritj |ƒ}nt|tj ƒr¡|r¡|j |j d |j ƒ}n|d}t|ƒdkrÐ|d}d}n¦t|ƒdkrù|d}|d}n}t|ƒ}|d}|d}xZtd t|ƒdƒD]?}|}|d}|| |d|d}|||}q3W|||S( s5 Evaluate an Hermite series at points x. If `c` is of length `n + 1`, this function returns the value: .. math:: p(x) = c_0 * H_0(x) + c_1 * H_1(x) + ... + c_n * H_n(x) The parameter `x` is converted to an array only if it is a tuple or a list, otherwise it is treated as a scalar. In either case, either `x` or its elements must support multiplication and addition both with themselves and with the elements of `c`. If `c` is a 1-D array, then `p(x)` will have the same shape as `x`. If `c` is multidimensional, then the shape of the result depends on the value of `tensor`. If `tensor` is true the shape will be c.shape[1:] + x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that scalars have shape (,). Trailing zeros in the coefficients will be used in the evaluation, so they should be avoided if efficiency is a concern. Parameters ---------- x : array_like, compatible object If `x` is a list or tuple, it is converted to an ndarray, otherwise it is left unchanged and treated as a scalar. In either case, `x` or its elements must support addition and multiplication with with themselves and with the elements of `c`. c : array_like Array of coefficients ordered so that the coefficients for terms of degree n are contained in c[n]. If `c` is multidimensional the remaining indices enumerate multiple polynomials. In the two dimensional case the coefficients may be thought of as stored in the columns of `c`. tensor : boolean, optional If True, the shape of the coefficient array is extended with ones on the right, one for each dimension of `x`. Scalars have dimension 0 for this action. The result is that every column of coefficients in `c` is evaluated for every element of `x`. If False, `x` is broadcast over the columns of `c` for the evaluation. This keyword is useful when `c` is multidimensional. The default value is True. .. versionadded:: 1.7.0 Returns ------- values : ndarray, algebra_like The shape of the return value is described above. See Also -------- hermval2d, hermgrid2d, hermval3d, hermgrid3d Notes ----- The evaluation uses Clenshaw recursion, aka synthetic division. Examples -------- >>> from numpy.polynomial.hermite import hermval >>> coef = [1,2,3] >>> hermval(1, coef) 11.0 >>> hermval([[1,2],[3,4]], coef) array([[ 11., 51.], [ 115., 203.]]) RXiRYis ?bBhHiIlLqQpPiiþÿÿÿiÿÿÿÿi(i(R6R7RGRZR[R\t isinstancettupleRgtasarraytndarraytreshapeR_R]R'R(( txR1ttensortx2R3R4RKR,R5((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRSs.E           cC`smy%tj||fddƒ\}}Wntk rDtdƒ‚nXt||ƒ}t||dtƒ}|S(sB Evaluate a 2-D Hermite series at points (x, y). This function returns the values: .. math:: p(x,y) = \sum_{i,j} c_{i,j} * H_i(x) * H_j(y) The parameters `x` and `y` are converted to arrays only if they are tuples or a lists, otherwise they are treated as a scalars and they must have the same shape after conversion. In either case, either `x` and `y` or their elements must support multiplication and addition both with themselves and with the elements of `c`. If `c` is a 1-D array a one is implicitly appended to its shape to make it 2-D. The shape of the result will be c.shape[2:] + x.shape. Parameters ---------- x, y : array_like, compatible objects The two dimensional series is evaluated at the points `(x, y)`, where `x` and `y` must have the same shape. If `x` or `y` is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged and if it isn't an ndarray it is treated as a scalar. c : array_like Array of coefficients ordered so that the coefficient of the term of multi-degree i,j is contained in ``c[i,j]``. If `c` has dimension greater than two the remaining indices enumerate multiple sets of coefficients. Returns ------- values : ndarray, compatible object The values of the two dimensional polynomial at points formed with pairs of corresponding values from `x` and `y`. See Also -------- hermval, hermgrid2d, hermval3d, hermgrid3d Notes ----- .. versionadded:: 1.7.0 RYisx, y are incompatibleRq(R6R7t ExceptionRSRR<(RptyR1((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR³s.% cC`s"t||ƒ}t||ƒ}|S(sÒ Evaluate a 2-D Hermite series on the Cartesian product of x and y. This function returns the values: .. math:: p(a,b) = \sum_{i,j} c_{i,j} * H_i(a) * H_j(b) where the points `(a, b)` consist of all pairs formed by taking `a` from `x` and `b` from `y`. The resulting points form a grid with `x` in the first dimension and `y` in the second. The parameters `x` and `y` are converted to arrays only if they are tuples or a lists, otherwise they are treated as a scalars. In either case, either `x` and `y` or their elements must support multiplication and addition both with themselves and with the elements of `c`. If `c` has fewer than two dimensions, ones are implicitly appended to its shape to make it 2-D. The shape of the result will be c.shape[2:] + x.shape. Parameters ---------- x, y : array_like, compatible objects The two dimensional series is evaluated at the points in the Cartesian product of `x` and `y`. If `x` or `y` is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged and, if it isn't an ndarray, it is treated as a scalar. c : array_like Array of coefficients ordered so that the coefficients for terms of degree i,j are contained in ``c[i,j]``. If `c` has dimension greater than two the remaining indices enumerate multiple sets of coefficients. Returns ------- values : ndarray, compatible object The values of the two dimensional polynomial at points in the Cartesian product of `x` and `y`. See Also -------- hermval, hermval2d, hermval3d, hermgrid3d Notes ----- .. versionadded:: 1.7.0 (R(RpRtR1((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRës2cC`sˆy+tj|||fddƒ\}}}Wntk rJtdƒ‚nXt||ƒ}t||dtƒ}t||dtƒ}|S(s¡ Evaluate a 3-D Hermite series at points (x, y, z). This function returns the values: .. math:: p(x,y,z) = \sum_{i,j,k} c_{i,j,k} * H_i(x) * H_j(y) * H_k(z) The parameters `x`, `y`, and `z` are converted to arrays only if they are tuples or a lists, otherwise they are treated as a scalars and they must have the same shape after conversion. In either case, either `x`, `y`, and `z` or their elements must support multiplication and addition both with themselves and with the elements of `c`. If `c` has fewer than 3 dimensions, ones are implicitly appended to its shape to make it 3-D. The shape of the result will be c.shape[3:] + x.shape. Parameters ---------- x, y, z : array_like, compatible object The three dimensional series is evaluated at the points `(x, y, z)`, where `x`, `y`, and `z` must have the same shape. If any of `x`, `y`, or `z` is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged and if it isn't an ndarray it is treated as a scalar. c : array_like Array of coefficients ordered so that the coefficient of the term of multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension greater than 3 the remaining indices enumerate multiple sets of coefficients. Returns ------- values : ndarray, compatible object The values of the multidimensional polynomial on points formed with triples of corresponding values from `x`, `y`, and `z`. See Also -------- hermval, hermval2d, hermgrid2d, hermgrid3d Notes ----- .. versionadded:: 1.7.0 RYisx, y, z are incompatibleRq(R6R7RsRSRR<(RpRttzR1((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR"s0+ cC`s1t||ƒ}t||ƒ}t||ƒ}|S(sN Evaluate a 3-D Hermite series on the Cartesian product of x, y, and z. This function returns the values: .. math:: p(a,b,c) = \sum_{i,j,k} c_{i,j,k} * H_i(a) * H_j(b) * H_k(c) where the points `(a, b, c)` consist of all triples formed by taking `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form a grid with `x` in the first dimension, `y` in the second, and `z` in the third. The parameters `x`, `y`, and `z` are converted to arrays only if they are tuples or a lists, otherwise they are treated as a scalars. In either case, either `x`, `y`, and `z` or their elements must support multiplication and addition both with themselves and with the elements of `c`. If `c` has fewer than three dimensions, ones are implicitly appended to its shape to make it 3-D. The shape of the result will be c.shape[3:] + x.shape + y.shape + z.shape. Parameters ---------- x, y, z : array_like, compatible objects The three dimensional series is evaluated at the points in the Cartesian product of `x`, `y`, and `z`. If `x`,`y`, or `z` is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged and, if it isn't an ndarray, it is treated as a scalar. c : array_like Array of coefficients ordered so that the coefficients for terms of degree i,j are contained in ``c[i,j]``. If `c` has dimension greater than two the remaining indices enumerate multiple sets of coefficients. Returns ------- values : ndarray, compatible object The values of the two dimensional polynomial at points in the Cartesian product of `x` and `y`. See Also -------- hermval, hermval2d, hermgrid2d, hermval3d Notes ----- .. versionadded:: 1.7.0 (R(RpRtRuR1((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR]s5cC`s't|ƒ}||kr'tdƒ‚n|dkrBtdƒ‚ntj|ddddƒd}|df|j}|j}tj|d|ƒ}|dd|d<|dkr|d }||d>> from numpy.polynomial.hermite import hermvander >>> x = np.array([-1, 0, 1]) >>> hermvander(x, 3) array([[ 1., -2., 2., 4.], [ 1., 0., -2., -0.], [ 1., 2., 2., -4.]]) sdeg must be integerisdeg must be non-negativeRYRXigRGiiÿÿÿÿ( RRRSR6R7R_RGRHR(R^(RpR*tidegtdimstdtyptvRrR,((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR˜s ,       5c C`sg|D]}t|ƒ^q}gt||ƒD]$\}}||koP|dk^q/}|ddgkrztdƒ‚n|\}}tj||fddƒd\}}t||ƒ} t||ƒ} | d | dddd…f} | j| jd d ƒS( s‘Pseudo-Vandermonde matrix of given degrees. Returns the pseudo-Vandermonde matrix of degrees `deg` and sample points `(x, y)`. The pseudo-Vandermonde matrix is defined by .. math:: V[..., (deg[1] + 1)*i + j] = H_i(x) * H_j(y), where `0 <= i <= deg[0]` and `0 <= j <= deg[1]`. The leading indices of `V` index the points `(x, y)` and the last index encodes the degrees of the Hermite polynomials. If ``V = hermvander2d(x, y, [xdeg, ydeg])``, then the columns of `V` correspond to the elements of a 2-D coefficient array `c` of shape (xdeg + 1, ydeg + 1) in the order .. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ... and ``np.dot(V, c.flat)`` and ``hermval2d(x, y, c)`` will be the same up to roundoff. This equivalence is useful both for least squares fitting and for the evaluation of a large number of 2-D Hermite series of the same degrees and sample points. Parameters ---------- x, y : array_like Arrays of point coordinates, all of the same shape. The dtypes will be converted to either float64 or complex128 depending on whether any of the elements are complex. Scalars are converted to 1-D arrays. deg : list of ints List of maximum degrees of the form [x_deg, y_deg]. Returns ------- vander2d : ndarray The shape of the returned matrix is ``x.shape + (order,)``, where :math:`order = (deg[0]+1)*(deg([1]+1)`. The dtype will be the same as the converted `x` and `y`. See Also -------- hermvander, hermvander3d. hermval2d, hermval3d Notes ----- .. versionadded:: 1.7.0 iis%degrees must be non-negative integersRYg.Niþÿÿÿiÿÿÿÿ(.N(iÿÿÿÿ( RRtzipRSR6R7RRTRoR_( RpRtR*tdRvtidtis_validtdegxtdegytvxtvyRy((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR ×s2: %!cC`s:g|D]}t|ƒ^q}gt||ƒD]$\}}||koP|dk^q/}|dddgkr}tdƒ‚n|\}} } tj|||fddƒd\}}}t||ƒ} t|| ƒ} t|| ƒ} | d | dddd…df| ddddd…f}|j|jd d ƒS( sPseudo-Vandermonde matrix of given degrees. Returns the pseudo-Vandermonde matrix of degrees `deg` and sample points `(x, y, z)`. If `l, m, n` are the given degrees in `x, y, z`, then The pseudo-Vandermonde matrix is defined by .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = H_i(x)*H_j(y)*H_k(z), where `0 <= i <= l`, `0 <= j <= m`, and `0 <= j <= n`. The leading indices of `V` index the points `(x, y, z)` and the last index encodes the degrees of the Hermite polynomials. If ``V = hermvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns of `V` correspond to the elements of a 3-D coefficient array `c` of shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},... and ``np.dot(V, c.flat)`` and ``hermval3d(x, y, z, c)`` will be the same up to roundoff. This equivalence is useful both for least squares fitting and for the evaluation of a large number of 3-D Hermite series of the same degrees and sample points. Parameters ---------- x, y, z : array_like Arrays of point coordinates, all of the same shape. The dtypes will be converted to either float64 or complex128 depending on whether any of the elements are complex. Scalars are converted to 1-D arrays. deg : list of ints List of maximum degrees of the form [x_deg, y_deg, z_deg]. Returns ------- vander3d : ndarray The shape of the returned matrix is ``x.shape + (order,)``, where :math:`order = (deg[0]+1)*(deg([1]+1)*(deg[2]+1)`. The dtype will be the same as the converted `x`, `y`, and `z`. See Also -------- hermvander, hermvander3d. hermval2d, hermval3d Notes ----- .. versionadded:: 1.7.0 iis%degrees must be non-negative integersRYg.Niýÿÿÿiÿÿÿÿ(.NN(iÿÿÿÿ( RRRzRSR6R7RRTRoR_(RpRtRuR*R{RvR|R}R~RtdegzR€RtvzRy((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR!s3:+>cC`sâtj|ƒd}tj|ƒd}tj|ƒ}|jdkse|jjdkse|jdkrttdƒ‚n|jƒdkr•tdƒ‚n|jdkr³tdƒ‚n|jdkrÑtdƒ‚n|jdksï|jd krþtd ƒ‚nt |ƒt |ƒkr%td ƒ‚n|jdkrV|}|d}t ||ƒ}nDtj |ƒ}|d }t |ƒ}t ||ƒd d …|f}|j } |j } |d k r'tj|ƒd}|jdkrétdƒ‚nt |ƒt |ƒkrtdƒ‚n| |} | |} n|d krUt |ƒtj|jƒj}nt| jjtjƒr¤tjtj| jƒtj| jƒjdƒƒ} n!tjtj| ƒjdƒƒ} d| | dk= 1.11.0 a list of integers specifying the degrees of the terms to include may be used instead. 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. If not None, the contribution of each point ``(x[i],y[i])`` to the fit is weighted by `w[i]`. Ideally the weights are chosen so that the errors of the products ``w[i]*y[i]`` all have the same variance. The default value is None. Returns ------- coef : ndarray, shape (M,) or (M, K) Hermite coefficients ordered from low to high. If `y` was 2-D, the coefficients for the data in column k of `y` are in column `k`. [residuals, rank, singular_values, rcond] : list These values are only returned if `full` = True resid -- sum of squared residuals of the least squares fit rank -- the numerical rank of the scaled Vandermonde matrix sv -- singular values of the scaled Vandermonde matrix rcond -- value of `rcond`. For more details, see `linalg.lstsq`. 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', RankWarning) See Also -------- chebfit, legfit, lagfit, polyfit, hermefit hermval : Evaluates a Hermite series. hermvander : Vandermonde matrix of Hermite series. hermweight : Hermite weight function linalg.lstsq : Computes a least-squares fit from the matrix. scipy.interpolate.UnivariateSpline : Computes spline fits. Notes ----- The solution is the coefficients of the Hermite series `p` that minimizes the sum of the weighted squared errors .. math:: E = \sum_j w_j^2 * |y_j - p(x_j)|^2, where the :math:`w_j` are the weights. This problem is solved by setting up the (typically) overdetermined matrix equation .. math:: V(x) * c = w * y, where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the coefficients to be solved for, `w` are the weights, `y` are the observed values. This equation is then solved using the singular value decomposition of `V`. If some of the singular values of `V` are so small that they are neglected, then a `RankWarning` will be issued. This means that the coefficient values may be poorly determined. Using a lower order fit will usually get rid of the warning. The `rcond` parameter can also be set to a value smaller than its default, but the resulting fit may be spurious and have large contributions from roundoff error. Fits using Hermite series are probably most useful when the data can be approximated by ``sqrt(w(x)) * p(x)``, where `w(x)` is the Hermite weight. In that case the weight ``sqrt(w(x[i])`` should be used together with data values ``y[i]/sqrt(w(x[i])``. The weight function is available as `hermweight`. References ---------- .. [1] Wikipedia, "Curve fitting", http://en.wikipedia.org/wiki/Curve_fitting Examples -------- >>> from numpy.polynomial.hermite import hermfit, hermval >>> x = np.linspace(-10, 10) >>> err = np.random.randn(len(x))/10 >>> y = hermval(x, [1, 2, 3]) + err >>> hermfit(x, y, 2) array([ 0.97902637, 1.99849131, 3.00006 ]) gitiuis0deg must be an int or non-empty 1-D array of intsexpected deg >= 0sexpected 1D vector for xsexpected non-empty vector for xisexpected 1D or 2D array for ys$expected x and y to have same lengthiÿÿÿÿNsexpected 1D vector for ws$expected x and w to have same lengthRGs!The fit may be poorly conditionedt stacklevel( R6RmR]RGtkindRCt TypeErrortminRSR'RR=tTRTtfinfotepst issubclassttypetcomplexfloatingtsqrttsquaretrealtimagtsumtlatlstsqtzerosR_twarningstwarnR%t RankWarning(RpRtR*trcondtfulltwtlmaxtordertvantlhstrhsR9R1tresidstranktstcctmsg((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRWsj|0         "7!+,  c C`s’tj|gƒ\}t|ƒdkr6tdƒ‚nt|ƒdkrktjd|d|dggƒSt|ƒd}tj||fd|jƒ}tjddtj dtj |ddd ƒƒfƒ}tj j |ƒd d d …}|j d ƒdd |d…}|j d ƒ|d |d…}tj d tj d|ƒƒ|d <||d <|d d …d fc||d d|d 8<|S( s’Return the scaled companion matrix of c. The basis polynomials are scaled so that the companion matrix is symmetric when `c` is an Hermite basis polynomial. This provides better eigenvalue estimates than the unscaled case and for basis polynomials the eigenvalues are guaranteed to be real if `numpy.linalg.eigvalsh` is used to obtain them. Parameters ---------- c : array_like 1-D array of Hermite series coefficients ordered from low to high degree. Returns ------- mat : ndarray Scaled companion matrix of dimensions (deg, deg). Notes ----- .. versionadded:: 1.7.0 is.Series must have maximum degree of at least 1.gà¿iiRGgð?g@iÿÿÿÿNgà?.(R%R&R'RSR6R7R–RGthstackRtarangetmultiplyt accumulateRo(R1R2tmatR9ttoptbot((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR" s#9  # 0cC`s˜tj|gƒ\}t|ƒdkr=tjgd|jƒSt|ƒdkrotjd|d|dgƒSt|ƒ}tj|ƒ}|j ƒ|S(s~ Compute the roots of a Hermite series. Return the roots (a.k.a. "zeros") of the polynomial .. math:: p(x) = \sum_i c[i] * H_i(x). Parameters ---------- c : 1-D array_like 1-D array of coefficients. Returns ------- out : ndarray Array of the roots of the series. If all the roots are real, then `out` is also real, otherwise it is complex. See Also -------- polyroots, legroots, lagroots, chebroots, hermeroots Notes ----- The root estimates are obtained as the eigenvalues of the companion matrix, Roots far from the origin of the complex plane may have large errors due to the numerical instability of the series for such values. Roots with multiplicity greater than 1 will also show larger errors as the value of the series near such points is relatively insensitive to errors in the roots. Isolated roots near the origin can be improved by a few iterations of Newton's method. The Hermite series basis polynomials aren't powers of `x` so the results of this function may seem unintuitive. Examples -------- >>> from numpy.polynomial.hermite import hermroots, hermfromroots >>> coef = hermfromroots([-1, 0, 1]) >>> coef array([ 0. , 0.25 , 0. , 0.125]) >>> hermroots(coef) array([ -1.00000000e+00, -1.38777878e-17, 1.00000000e+00]) iRGigà¿i( R%R&R'R6R7RGR"R”teigvalsR=(R1RBR@((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRMs/   cC`så|dkr5tj|jƒtjtjtjƒƒSd}dtjtjtjƒƒ}t|ƒ}xct|dƒD]Q}|}| tj|d|ƒ}|||tjd|ƒ}|d}qwW|||tjdƒS(sŸ Evaluate a normalized Hermite polynomial. Compute the value of the normalized Hermite polynomial of degree ``n`` at the points ``x``. Parameters ---------- x : ndarray of double. Points at which to evaluate the function n : int Degree of the normalized Hermite function to be evaluated. Returns ------- values : ndarray The shape of the return value is described above. Notes ----- .. versionadded:: 1.10.0 This function is needed for finding the Gauss points and integration weights for high degrees. The values of the standard Hermite functions overflow when n >= 207. iggð?ig@i(R6R;R_RtpitfloatR((RpR2R3R4RKR,R5((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyt_normed_hermite_nˆs ) c C`sOt|ƒ}||ks$|dkr3tdƒ‚ntjdg|dgdtjƒ}t|ƒ}tj|ƒ}t||ƒ}t||dƒtj d|ƒ}|||8}t||dƒ}|tj |ƒj ƒ}d||}||ddd…d}||ddd…d}|tj tj ƒ|j ƒ9}||fS(sö Gauss-Hermite quadrature. Computes the sample points and weights for Gauss-Hermite quadrature. These sample points and weights will correctly integrate polynomials of degree :math:`2*deg - 1` or less over the interval :math:`[-\inf, \inf]` with the weight function :math:`f(x) = \exp(-x^2)`. Parameters ---------- deg : int Number of sample points and weights. It must be >= 1. Returns ------- x : ndarray 1-D ndarray containing the sample points. y : ndarray 1-D ndarray containing the weights. Notes ----- .. versionadded:: 1.7.0 The results have only been tested up to degree 100, higher degrees may be problematic. The weights are determined by using the fact that .. math:: w_k = c / (H'_n(x_k) * H_{n-1}(x_k)) where :math:`c` is a constant independent of :math:`k` and :math:`x_k` is the k'th root of :math:`H_n`, and then scaling the results to get the right value when integrating 1. is"deg must be a non-negative integeriRGiNiÿÿÿÿ(RRRSR6R7tfloat64R"R”teigvalshR±RtabstmaxR¯R“( R*RvR1RBRptdytdftfmRœ((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR#³s $ & $ cC`stj|d ƒ}|S(sö Weight function of the Hermite polynomials. The weight function is :math:`\exp(-x^2)` and the interval of integration is :math:`[-\inf, \inf]`. the Hermite polynomials are orthogonal, but not normalized, with respect to this weight function. Parameters ---------- x : array_like Values at which the weight function will be computed. Returns ------- w : ndarray The weight function at `x`. Notes ----- .. versionadded:: 1.7.0 i(R6texp(RpRœ((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyR$öscB`sÂeZdZeeƒZeeƒZeeƒZ ee ƒZ ee ƒZ eeƒZeeƒZeeƒZeeƒZeeƒZeeƒZeeƒZdZejeƒZ ejeƒZ!RS(sAn Hermite series class. The Hermite class provides the standard Python numerical methods '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the attributes and methods listed in the `ABCPolyBase` documentation. Parameters ---------- coef : array_like Hermite coefficients in order of increasing degree, i.e, ``(1, 2, 3)`` gives ``1*H_0(x) + 2*H_1(X) + 3*H_2(x)``. domain : (2,) array_like, optional Domain to use. The interval ``[domain[0], domain[1]]`` is mapped to the interval ``[window[0], window[1]]`` by shifting and scaling. The default value is [-1, 1]. window : (2,) array_like, optional Window, see `domain` for its use. The default value is [-1, 1]. .. versionadded:: 1.6.0 therm("t__name__t __module__t__doc__t staticmethodR t_addR t_subRt_mulRt_divRt_powRt_valRt_intRt_derRt_fitR t_lineRt_rootsRt _fromrootstnicknameR6R7R tdomaintwindow(((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyRs             gà?(8R½t __future__RRRR—tnumpyR6t numpy.linalgtlinalgR”tnumpy.core.multiarrayRtRR%t _polybaseRt__all__ttrimcoefRRRR7R RRRR RR R R RRRRRtTrueRRRRRRR R!RTR<RR"RR±R#R$R(((s7/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/hermite.pyt;sZ    . ? $ C 0 1 1 B C 6W~ ` 8 7 ; ; ? ? AÉ - ; + C