Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/numpy/polynomial/hermite.py
7763 views
"""1==============================================================2Hermite Series, "Physicists" (:mod:`numpy.polynomial.hermite`)3==============================================================45This module provides a number of objects (mostly functions) useful for6dealing with Hermite series, including a `Hermite` class that7encapsulates the usual arithmetic operations. (General information8on how this module represents and works with such polynomials is in the9docstring for its "parent" sub-package, `numpy.polynomial`).1011Classes12-------13.. autosummary::14:toctree: generated/1516Hermite1718Constants19---------20.. autosummary::21:toctree: generated/2223hermdomain24hermzero25hermone26hermx2728Arithmetic29----------30.. autosummary::31:toctree: generated/3233hermadd34hermsub35hermmulx36hermmul37hermdiv38hermpow39hermval40hermval2d41hermval3d42hermgrid2d43hermgrid3d4445Calculus46--------47.. autosummary::48:toctree: generated/4950hermder51hermint5253Misc Functions54--------------55.. autosummary::56:toctree: generated/5758hermfromroots59hermroots60hermvander61hermvander2d62hermvander3d63hermgauss64hermweight65hermcompanion66hermfit67hermtrim68hermline69herm2poly70poly2herm7172See also73--------74`numpy.polynomial`7576"""77import numpy as np78import numpy.linalg as la79from numpy.core.multiarray import normalize_axis_index8081from . import polyutils as pu82from ._polybase import ABCPolyBase8384__all__ = [85'hermzero', 'hermone', 'hermx', 'hermdomain', 'hermline', 'hermadd',86'hermsub', 'hermmulx', 'hermmul', 'hermdiv', 'hermpow', 'hermval',87'hermder', 'hermint', 'herm2poly', 'poly2herm', 'hermfromroots',88'hermvander', 'hermfit', 'hermtrim', 'hermroots', 'Hermite',89'hermval2d', 'hermval3d', 'hermgrid2d', 'hermgrid3d', 'hermvander2d',90'hermvander3d', 'hermcompanion', 'hermgauss', 'hermweight']9192hermtrim = pu.trimcoef939495def poly2herm(pol):96"""97poly2herm(pol)9899Convert a polynomial to a Hermite series.100101Convert an array representing the coefficients of a polynomial (relative102to the "standard" basis) ordered from lowest degree to highest, to an103array of the coefficients of the equivalent Hermite series, ordered104from lowest to highest degree.105106Parameters107----------108pol : array_like1091-D array containing the polynomial coefficients110111Returns112-------113c : ndarray1141-D array containing the coefficients of the equivalent Hermite115series.116117See Also118--------119herm2poly120121Notes122-----123The easy way to do conversions between polynomial basis sets124is to use the convert method of a class instance.125126Examples127--------128>>> from numpy.polynomial.hermite import poly2herm129>>> poly2herm(np.arange(4))130array([1. , 2.75 , 0.5 , 0.375])131132"""133[pol] = pu.as_series([pol])134deg = len(pol) - 1135res = 0136for i in range(deg, -1, -1):137res = hermadd(hermmulx(res), pol[i])138return res139140141def herm2poly(c):142"""143Convert a Hermite series to a polynomial.144145Convert an array representing the coefficients of a Hermite series,146ordered from lowest degree to highest, to an array of the coefficients147of the equivalent polynomial (relative to the "standard" basis) ordered148from lowest to highest degree.149150Parameters151----------152c : array_like1531-D array containing the Hermite series coefficients, ordered154from lowest order term to highest.155156Returns157-------158pol : ndarray1591-D array containing the coefficients of the equivalent polynomial160(relative to the "standard" basis) ordered from lowest order term161to highest.162163See Also164--------165poly2herm166167Notes168-----169The easy way to do conversions between polynomial basis sets170is to use the convert method of a class instance.171172Examples173--------174>>> from numpy.polynomial.hermite import herm2poly175>>> herm2poly([ 1. , 2.75 , 0.5 , 0.375])176array([0., 1., 2., 3.])177178"""179from .polynomial import polyadd, polysub, polymulx180181[c] = pu.as_series([c])182n = len(c)183if n == 1:184return c185if n == 2:186c[1] *= 2187return c188else:189c0 = c[-2]190c1 = c[-1]191# i is the current degree of c1192for i in range(n - 1, 1, -1):193tmp = c0194c0 = polysub(c[i - 2], c1*(2*(i - 1)))195c1 = polyadd(tmp, polymulx(c1)*2)196return polyadd(c0, polymulx(c1)*2)197198#199# These are constant arrays are of integer type so as to be compatible200# with the widest range of other types, such as Decimal.201#202203# Hermite204hermdomain = np.array([-1, 1])205206# Hermite coefficients representing zero.207hermzero = np.array([0])208209# Hermite coefficients representing one.210hermone = np.array([1])211212# Hermite coefficients representing the identity x.213hermx = np.array([0, 1/2])214215216def hermline(off, scl):217"""218Hermite series whose graph is a straight line.219220221222Parameters223----------224off, scl : scalars225The specified line is given by ``off + scl*x``.226227Returns228-------229y : ndarray230This module's representation of the Hermite series for231``off + scl*x``.232233See Also234--------235numpy.polynomial.polynomial.polyline236numpy.polynomial.chebyshev.chebline237numpy.polynomial.legendre.legline238numpy.polynomial.laguerre.lagline239numpy.polynomial.hermite_e.hermeline240241Examples242--------243>>> from numpy.polynomial.hermite import hermline, hermval244>>> hermval(0,hermline(3, 2))2453.0246>>> hermval(1,hermline(3, 2))2475.0248249"""250if scl != 0:251return np.array([off, scl/2])252else:253return np.array([off])254255256def hermfromroots(roots):257"""258Generate a Hermite series with given roots.259260The function returns the coefficients of the polynomial261262.. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),263264in Hermite form, where the `r_n` are the roots specified in `roots`.265If a zero has multiplicity n, then it must appear in `roots` n times.266For instance, if 2 is a root of multiplicity three and 3 is a root of267multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The268roots can appear in any order.269270If the returned coefficients are `c`, then271272.. math:: p(x) = c_0 + c_1 * H_1(x) + ... + c_n * H_n(x)273274The coefficient of the last term is not generally 1 for monic275polynomials in Hermite form.276277Parameters278----------279roots : array_like280Sequence containing the roots.281282Returns283-------284out : ndarray2851-D array of coefficients. If all roots are real then `out` is a286real array, if some of the roots are complex, then `out` is complex287even if all the coefficients in the result are real (see Examples288below).289290See Also291--------292numpy.polynomial.polynomial.polyfromroots293numpy.polynomial.legendre.legfromroots294numpy.polynomial.laguerre.lagfromroots295numpy.polynomial.chebyshev.chebfromroots296numpy.polynomial.hermite_e.hermefromroots297298Examples299--------300>>> from numpy.polynomial.hermite import hermfromroots, hermval301>>> coef = hermfromroots((-1, 0, 1))302>>> hermval((-1, 0, 1), coef)303array([0., 0., 0.])304>>> coef = hermfromroots((-1j, 1j))305>>> hermval((-1j, 1j), coef)306array([0.+0.j, 0.+0.j])307308"""309return pu._fromroots(hermline, hermmul, roots)310311312def hermadd(c1, c2):313"""314Add one Hermite series to another.315316Returns the sum of two Hermite series `c1` + `c2`. The arguments317are sequences of coefficients ordered from lowest order term to318highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.319320Parameters321----------322c1, c2 : array_like3231-D arrays of Hermite series coefficients ordered from low to324high.325326Returns327-------328out : ndarray329Array representing the Hermite series of their sum.330331See Also332--------333hermsub, hermmulx, hermmul, hermdiv, hermpow334335Notes336-----337Unlike multiplication, division, etc., the sum of two Hermite series338is a Hermite series (without having to "reproject" the result onto339the basis set) so addition, just like that of "standard" polynomials,340is simply "component-wise."341342Examples343--------344>>> from numpy.polynomial.hermite import hermadd345>>> hermadd([1, 2, 3], [1, 2, 3, 4])346array([2., 4., 6., 4.])347348"""349return pu._add(c1, c2)350351352def hermsub(c1, c2):353"""354Subtract one Hermite series from another.355356Returns the difference of two Hermite series `c1` - `c2`. The357sequences of coefficients are from lowest order term to highest, i.e.,358[1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.359360Parameters361----------362c1, c2 : array_like3631-D arrays of Hermite series coefficients ordered from low to364high.365366Returns367-------368out : ndarray369Of Hermite series coefficients representing their difference.370371See Also372--------373hermadd, hermmulx, hermmul, hermdiv, hermpow374375Notes376-----377Unlike multiplication, division, etc., the difference of two Hermite378series is a Hermite series (without having to "reproject" the result379onto the basis set) so subtraction, just like that of "standard"380polynomials, is simply "component-wise."381382Examples383--------384>>> from numpy.polynomial.hermite import hermsub385>>> hermsub([1, 2, 3, 4], [1, 2, 3])386array([0., 0., 0., 4.])387388"""389return pu._sub(c1, c2)390391392def hermmulx(c):393"""Multiply a Hermite series by x.394395Multiply the Hermite series `c` by x, where x is the independent396variable.397398399Parameters400----------401c : array_like4021-D array of Hermite series coefficients ordered from low to403high.404405Returns406-------407out : ndarray408Array representing the result of the multiplication.409410See Also411--------412hermadd, hermsub, hermmul, hermdiv, hermpow413414Notes415-----416The multiplication uses the recursion relationship for Hermite417polynomials in the form418419.. math::420421xP_i(x) = (P_{i + 1}(x)/2 + i*P_{i - 1}(x))422423Examples424--------425>>> from numpy.polynomial.hermite import hermmulx426>>> hermmulx([1, 2, 3])427array([2. , 6.5, 1. , 1.5])428429"""430# c is a trimmed copy431[c] = pu.as_series([c])432# The zero series needs special treatment433if len(c) == 1 and c[0] == 0:434return c435436prd = np.empty(len(c) + 1, dtype=c.dtype)437prd[0] = c[0]*0438prd[1] = c[0]/2439for i in range(1, len(c)):440prd[i + 1] = c[i]/2441prd[i - 1] += c[i]*i442return prd443444445def hermmul(c1, c2):446"""447Multiply one Hermite series by another.448449Returns the product of two Hermite series `c1` * `c2`. The arguments450are sequences of coefficients, from lowest order "term" to highest,451e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.452453Parameters454----------455c1, c2 : array_like4561-D arrays of Hermite series coefficients ordered from low to457high.458459Returns460-------461out : ndarray462Of Hermite series coefficients representing their product.463464See Also465--------466hermadd, hermsub, hermmulx, hermdiv, hermpow467468Notes469-----470In general, the (polynomial) product of two C-series results in terms471that are not in the Hermite polynomial basis set. Thus, to express472the product as a Hermite series, it is necessary to "reproject" the473product onto said basis set, which may produce "unintuitive" (but474correct) results; see Examples section below.475476Examples477--------478>>> from numpy.polynomial.hermite import hermmul479>>> hermmul([1, 2, 3], [0, 1, 2])480array([52., 29., 52., 7., 6.])481482"""483# s1, s2 are trimmed copies484[c1, c2] = pu.as_series([c1, c2])485486if len(c1) > len(c2):487c = c2488xs = c1489else:490c = c1491xs = c2492493if len(c) == 1:494c0 = c[0]*xs495c1 = 0496elif len(c) == 2:497c0 = c[0]*xs498c1 = c[1]*xs499else:500nd = len(c)501c0 = c[-2]*xs502c1 = c[-1]*xs503for i in range(3, len(c) + 1):504tmp = c0505nd = nd - 1506c0 = hermsub(c[-i]*xs, c1*(2*(nd - 1)))507c1 = hermadd(tmp, hermmulx(c1)*2)508return hermadd(c0, hermmulx(c1)*2)509510511def hermdiv(c1, c2):512"""513Divide one Hermite series by another.514515Returns the quotient-with-remainder of two Hermite series516`c1` / `c2`. The arguments are sequences of coefficients from lowest517order "term" to highest, e.g., [1,2,3] represents the series518``P_0 + 2*P_1 + 3*P_2``.519520Parameters521----------522c1, c2 : array_like5231-D arrays of Hermite series coefficients ordered from low to524high.525526Returns527-------528[quo, rem] : ndarrays529Of Hermite series coefficients representing the quotient and530remainder.531532See Also533--------534hermadd, hermsub, hermmulx, hermmul, hermpow535536Notes537-----538In general, the (polynomial) division of one Hermite series by another539results in quotient and remainder terms that are not in the Hermite540polynomial basis set. Thus, to express these results as a Hermite541series, it is necessary to "reproject" the results onto the Hermite542basis set, which may produce "unintuitive" (but correct) results; see543Examples section below.544545Examples546--------547>>> from numpy.polynomial.hermite import hermdiv548>>> hermdiv([ 52., 29., 52., 7., 6.], [0, 1, 2])549(array([1., 2., 3.]), array([0.]))550>>> hermdiv([ 54., 31., 52., 7., 6.], [0, 1, 2])551(array([1., 2., 3.]), array([2., 2.]))552>>> hermdiv([ 53., 30., 52., 7., 6.], [0, 1, 2])553(array([1., 2., 3.]), array([1., 1.]))554555"""556return pu._div(hermmul, c1, c2)557558559def hermpow(c, pow, maxpower=16):560"""Raise a Hermite series to a power.561562Returns the Hermite series `c` raised to the power `pow`. The563argument `c` is a sequence of coefficients ordered from low to high.564i.e., [1,2,3] is the series ``P_0 + 2*P_1 + 3*P_2.``565566Parameters567----------568c : array_like5691-D array of Hermite series coefficients ordered from low to570high.571pow : integer572Power to which the series will be raised573maxpower : integer, optional574Maximum power allowed. This is mainly to limit growth of the series575to unmanageable size. Default is 16576577Returns578-------579coef : ndarray580Hermite series of power.581582See Also583--------584hermadd, hermsub, hermmulx, hermmul, hermdiv585586Examples587--------588>>> from numpy.polynomial.hermite import hermpow589>>> hermpow([1, 2, 3], 2)590array([81., 52., 82., 12., 9.])591592"""593return pu._pow(hermmul, c, pow, maxpower)594595596def hermder(c, m=1, scl=1, axis=0):597"""598Differentiate a Hermite series.599600Returns the Hermite series coefficients `c` differentiated `m` times601along `axis`. At each iteration the result is multiplied by `scl` (the602scaling factor is for use in a linear change of variable). The argument603`c` is an array of coefficients from low to high degree along each604axis, e.g., [1,2,3] represents the series ``1*H_0 + 2*H_1 + 3*H_2``605while [[1,2],[1,2]] represents ``1*H_0(x)*H_0(y) + 1*H_1(x)*H_0(y) +6062*H_0(x)*H_1(y) + 2*H_1(x)*H_1(y)`` if axis=0 is ``x`` and axis=1 is607``y``.608609Parameters610----------611c : array_like612Array of Hermite series coefficients. If `c` is multidimensional the613different axis correspond to different variables with the degree in614each axis given by the corresponding index.615m : int, optional616Number of derivatives taken, must be non-negative. (Default: 1)617scl : scalar, optional618Each differentiation is multiplied by `scl`. The end result is619multiplication by ``scl**m``. This is for use in a linear change of620variable. (Default: 1)621axis : int, optional622Axis over which the derivative is taken. (Default: 0).623624.. versionadded:: 1.7.0625626Returns627-------628der : ndarray629Hermite series of the derivative.630631See Also632--------633hermint634635Notes636-----637In general, the result of differentiating a Hermite series does not638resemble the same operation on a power series. Thus the result of this639function may be "unintuitive," albeit correct; see Examples section640below.641642Examples643--------644>>> from numpy.polynomial.hermite import hermder645>>> hermder([ 1. , 0.5, 0.5, 0.5])646array([1., 2., 3.])647>>> hermder([-0.5, 1./2., 1./8., 1./12., 1./16.], m=2)648array([1., 2., 3.])649650"""651c = np.array(c, ndmin=1, copy=True)652if c.dtype.char in '?bBhHiIlLqQpP':653c = c.astype(np.double)654cnt = pu._deprecate_as_int(m, "the order of derivation")655iaxis = pu._deprecate_as_int(axis, "the axis")656if cnt < 0:657raise ValueError("The order of derivation must be non-negative")658iaxis = normalize_axis_index(iaxis, c.ndim)659660if cnt == 0:661return c662663c = np.moveaxis(c, iaxis, 0)664n = len(c)665if cnt >= n:666c = c[:1]*0667else:668for i in range(cnt):669n = n - 1670c *= scl671der = np.empty((n,) + c.shape[1:], dtype=c.dtype)672for j in range(n, 0, -1):673der[j - 1] = (2*j)*c[j]674c = der675c = np.moveaxis(c, 0, iaxis)676return c677678679def hermint(c, m=1, k=[], lbnd=0, scl=1, axis=0):680"""681Integrate a Hermite series.682683Returns the Hermite series coefficients `c` integrated `m` times from684`lbnd` along `axis`. At each iteration the resulting series is685**multiplied** by `scl` and an integration constant, `k`, is added.686The scaling factor is for use in a linear change of variable. ("Buyer687beware": note that, depending on what one is doing, one may want `scl`688to be the reciprocal of what one might expect; for more information,689see the Notes section below.) The argument `c` is an array of690coefficients from low to high degree along each axis, e.g., [1,2,3]691represents the series ``H_0 + 2*H_1 + 3*H_2`` while [[1,2],[1,2]]692represents ``1*H_0(x)*H_0(y) + 1*H_1(x)*H_0(y) + 2*H_0(x)*H_1(y) +6932*H_1(x)*H_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.694695Parameters696----------697c : array_like698Array of Hermite series coefficients. If c is multidimensional the699different axis correspond to different variables with the degree in700each axis given by the corresponding index.701m : int, optional702Order of integration, must be positive. (Default: 1)703k : {[], list, scalar}, optional704Integration constant(s). The value of the first integral at705``lbnd`` is the first value in the list, the value of the second706integral at ``lbnd`` is the second value, etc. If ``k == []`` (the707default), all constants are set to zero. If ``m == 1``, a single708scalar can be given instead of a list.709lbnd : scalar, optional710The lower bound of the integral. (Default: 0)711scl : scalar, optional712Following each integration the result is *multiplied* by `scl`713before the integration constant is added. (Default: 1)714axis : int, optional715Axis over which the integral is taken. (Default: 0).716717.. versionadded:: 1.7.0718719Returns720-------721S : ndarray722Hermite series coefficients of the integral.723724Raises725------726ValueError727If ``m < 0``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or728``np.ndim(scl) != 0``.729730See Also731--------732hermder733734Notes735-----736Note that the result of each integration is *multiplied* by `scl`.737Why is this important to note? Say one is making a linear change of738variable :math:`u = ax + b` in an integral relative to `x`. Then739:math:`dx = du/a`, so one will need to set `scl` equal to740:math:`1/a` - perhaps not what one would have first thought.741742Also note that, in general, the result of integrating a C-series needs743to be "reprojected" onto the C-series basis set. Thus, typically,744the result of this function is "unintuitive," albeit correct; see745Examples section below.746747Examples748--------749>>> from numpy.polynomial.hermite import hermint750>>> hermint([1,2,3]) # integrate once, value 0 at 0.751array([1. , 0.5, 0.5, 0.5])752>>> hermint([1,2,3], m=2) # integrate twice, value & deriv 0 at 0753array([-0.5 , 0.5 , 0.125 , 0.08333333, 0.0625 ]) # may vary754>>> hermint([1,2,3], k=1) # integrate once, value 1 at 0.755array([2. , 0.5, 0.5, 0.5])756>>> hermint([1,2,3], lbnd=-1) # integrate once, value 0 at -1757array([-2. , 0.5, 0.5, 0.5])758>>> hermint([1,2,3], m=2, k=[1,2], lbnd=-1)759array([ 1.66666667, -0.5 , 0.125 , 0.08333333, 0.0625 ]) # may vary760761"""762c = np.array(c, ndmin=1, copy=True)763if c.dtype.char in '?bBhHiIlLqQpP':764c = c.astype(np.double)765if not np.iterable(k):766k = [k]767cnt = pu._deprecate_as_int(m, "the order of integration")768iaxis = pu._deprecate_as_int(axis, "the axis")769if cnt < 0:770raise ValueError("The order of integration must be non-negative")771if len(k) > cnt:772raise ValueError("Too many integration constants")773if np.ndim(lbnd) != 0:774raise ValueError("lbnd must be a scalar.")775if np.ndim(scl) != 0:776raise ValueError("scl must be a scalar.")777iaxis = normalize_axis_index(iaxis, c.ndim)778779if cnt == 0:780return c781782c = np.moveaxis(c, iaxis, 0)783k = list(k) + [0]*(cnt - len(k))784for i in range(cnt):785n = len(c)786c *= scl787if n == 1 and np.all(c[0] == 0):788c[0] += k[i]789else:790tmp = np.empty((n + 1,) + c.shape[1:], dtype=c.dtype)791tmp[0] = c[0]*0792tmp[1] = c[0]/2793for j in range(1, n):794tmp[j + 1] = c[j]/(2*(j + 1))795tmp[0] += k[i] - hermval(lbnd, tmp)796c = tmp797c = np.moveaxis(c, 0, iaxis)798return c799800801def hermval(x, c, tensor=True):802"""803Evaluate an Hermite series at points x.804805If `c` is of length `n + 1`, this function returns the value:806807.. math:: p(x) = c_0 * H_0(x) + c_1 * H_1(x) + ... + c_n * H_n(x)808809The parameter `x` is converted to an array only if it is a tuple or a810list, otherwise it is treated as a scalar. In either case, either `x`811or its elements must support multiplication and addition both with812themselves and with the elements of `c`.813814If `c` is a 1-D array, then `p(x)` will have the same shape as `x`. If815`c` is multidimensional, then the shape of the result depends on the816value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +817x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that818scalars have shape (,).819820Trailing zeros in the coefficients will be used in the evaluation, so821they should be avoided if efficiency is a concern.822823Parameters824----------825x : array_like, compatible object826If `x` is a list or tuple, it is converted to an ndarray, otherwise827it is left unchanged and treated as a scalar. In either case, `x`828or its elements must support addition and multiplication with829with themselves and with the elements of `c`.830c : array_like831Array of coefficients ordered so that the coefficients for terms of832degree n are contained in c[n]. If `c` is multidimensional the833remaining indices enumerate multiple polynomials. In the two834dimensional case the coefficients may be thought of as stored in835the columns of `c`.836tensor : boolean, optional837If True, the shape of the coefficient array is extended with ones838on the right, one for each dimension of `x`. Scalars have dimension 0839for this action. The result is that every column of coefficients in840`c` is evaluated for every element of `x`. If False, `x` is broadcast841over the columns of `c` for the evaluation. This keyword is useful842when `c` is multidimensional. The default value is True.843844.. versionadded:: 1.7.0845846Returns847-------848values : ndarray, algebra_like849The shape of the return value is described above.850851See Also852--------853hermval2d, hermgrid2d, hermval3d, hermgrid3d854855Notes856-----857The evaluation uses Clenshaw recursion, aka synthetic division.858859Examples860--------861>>> from numpy.polynomial.hermite import hermval862>>> coef = [1,2,3]863>>> hermval(1, coef)86411.0865>>> hermval([[1,2],[3,4]], coef)866array([[ 11., 51.],867[115., 203.]])868869"""870c = np.array(c, ndmin=1, copy=False)871if c.dtype.char in '?bBhHiIlLqQpP':872c = c.astype(np.double)873if isinstance(x, (tuple, list)):874x = np.asarray(x)875if isinstance(x, np.ndarray) and tensor:876c = c.reshape(c.shape + (1,)*x.ndim)877878x2 = x*2879if len(c) == 1:880c0 = c[0]881c1 = 0882elif len(c) == 2:883c0 = c[0]884c1 = c[1]885else:886nd = len(c)887c0 = c[-2]888c1 = c[-1]889for i in range(3, len(c) + 1):890tmp = c0891nd = nd - 1892c0 = c[-i] - c1*(2*(nd - 1))893c1 = tmp + c1*x2894return c0 + c1*x2895896897def hermval2d(x, y, c):898"""899Evaluate a 2-D Hermite series at points (x, y).900901This function returns the values:902903.. math:: p(x,y) = \\sum_{i,j} c_{i,j} * H_i(x) * H_j(y)904905The parameters `x` and `y` are converted to arrays only if they are906tuples or a lists, otherwise they are treated as a scalars and they907must have the same shape after conversion. In either case, either `x`908and `y` or their elements must support multiplication and addition both909with themselves and with the elements of `c`.910911If `c` is a 1-D array a one is implicitly appended to its shape to make912it 2-D. The shape of the result will be c.shape[2:] + x.shape.913914Parameters915----------916x, y : array_like, compatible objects917The two dimensional series is evaluated at the points `(x, y)`,918where `x` and `y` must have the same shape. If `x` or `y` is a list919or tuple, it is first converted to an ndarray, otherwise it is left920unchanged and if it isn't an ndarray it is treated as a scalar.921c : array_like922Array of coefficients ordered so that the coefficient of the term923of multi-degree i,j is contained in ``c[i,j]``. If `c` has924dimension greater than two the remaining indices enumerate multiple925sets of coefficients.926927Returns928-------929values : ndarray, compatible object930The values of the two dimensional polynomial at points formed with931pairs of corresponding values from `x` and `y`.932933See Also934--------935hermval, hermgrid2d, hermval3d, hermgrid3d936937Notes938-----939940.. versionadded:: 1.7.0941942"""943return pu._valnd(hermval, c, x, y)944945946def hermgrid2d(x, y, c):947"""948Evaluate a 2-D Hermite series on the Cartesian product of x and y.949950This function returns the values:951952.. math:: p(a,b) = \\sum_{i,j} c_{i,j} * H_i(a) * H_j(b)953954where the points `(a, b)` consist of all pairs formed by taking955`a` from `x` and `b` from `y`. The resulting points form a grid with956`x` in the first dimension and `y` in the second.957958The parameters `x` and `y` are converted to arrays only if they are959tuples or a lists, otherwise they are treated as a scalars. In either960case, either `x` and `y` or their elements must support multiplication961and addition both with themselves and with the elements of `c`.962963If `c` has fewer than two dimensions, ones are implicitly appended to964its shape to make it 2-D. The shape of the result will be c.shape[2:] +965x.shape.966967Parameters968----------969x, y : array_like, compatible objects970The two dimensional series is evaluated at the points in the971Cartesian product of `x` and `y`. If `x` or `y` is a list or972tuple, it is first converted to an ndarray, otherwise it is left973unchanged and, if it isn't an ndarray, it is treated as a scalar.974c : array_like975Array of coefficients ordered so that the coefficients for terms of976degree i,j are contained in ``c[i,j]``. If `c` has dimension977greater than two the remaining indices enumerate multiple sets of978coefficients.979980Returns981-------982values : ndarray, compatible object983The values of the two dimensional polynomial at points in the Cartesian984product of `x` and `y`.985986See Also987--------988hermval, hermval2d, hermval3d, hermgrid3d989990Notes991-----992993.. versionadded:: 1.7.0994995"""996return pu._gridnd(hermval, c, x, y)997998999def hermval3d(x, y, z, c):1000"""1001Evaluate a 3-D Hermite series at points (x, y, z).10021003This function returns the values:10041005.. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * H_i(x) * H_j(y) * H_k(z)10061007The parameters `x`, `y`, and `z` are converted to arrays only if1008they are tuples or a lists, otherwise they are treated as a scalars and1009they must have the same shape after conversion. In either case, either1010`x`, `y`, and `z` or their elements must support multiplication and1011addition both with themselves and with the elements of `c`.10121013If `c` has fewer than 3 dimensions, ones are implicitly appended to its1014shape to make it 3-D. The shape of the result will be c.shape[3:] +1015x.shape.10161017Parameters1018----------1019x, y, z : array_like, compatible object1020The three dimensional series is evaluated at the points1021`(x, y, z)`, where `x`, `y`, and `z` must have the same shape. If1022any of `x`, `y`, or `z` is a list or tuple, it is first converted1023to an ndarray, otherwise it is left unchanged and if it isn't an1024ndarray it is treated as a scalar.1025c : array_like1026Array of coefficients ordered so that the coefficient of the term of1027multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension1028greater than 3 the remaining indices enumerate multiple sets of1029coefficients.10301031Returns1032-------1033values : ndarray, compatible object1034The values of the multidimensional polynomial on points formed with1035triples of corresponding values from `x`, `y`, and `z`.10361037See Also1038--------1039hermval, hermval2d, hermgrid2d, hermgrid3d10401041Notes1042-----10431044.. versionadded:: 1.7.010451046"""1047return pu._valnd(hermval, c, x, y, z)104810491050def hermgrid3d(x, y, z, c):1051"""1052Evaluate a 3-D Hermite series on the Cartesian product of x, y, and z.10531054This function returns the values:10551056.. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * H_i(a) * H_j(b) * H_k(c)10571058where the points `(a, b, c)` consist of all triples formed by taking1059`a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form1060a grid with `x` in the first dimension, `y` in the second, and `z` in1061the third.10621063The parameters `x`, `y`, and `z` are converted to arrays only if they1064are tuples or a lists, otherwise they are treated as a scalars. In1065either case, either `x`, `y`, and `z` or their elements must support1066multiplication and addition both with themselves and with the elements1067of `c`.10681069If `c` has fewer than three dimensions, ones are implicitly appended to1070its shape to make it 3-D. The shape of the result will be c.shape[3:] +1071x.shape + y.shape + z.shape.10721073Parameters1074----------1075x, y, z : array_like, compatible objects1076The three dimensional series is evaluated at the points in the1077Cartesian product of `x`, `y`, and `z`. If `x`,`y`, or `z` is a1078list or tuple, it is first converted to an ndarray, otherwise it is1079left unchanged and, if it isn't an ndarray, it is treated as a1080scalar.1081c : array_like1082Array of coefficients ordered so that the coefficients for terms of1083degree i,j are contained in ``c[i,j]``. If `c` has dimension1084greater than two the remaining indices enumerate multiple sets of1085coefficients.10861087Returns1088-------1089values : ndarray, compatible object1090The values of the two dimensional polynomial at points in the Cartesian1091product of `x` and `y`.10921093See Also1094--------1095hermval, hermval2d, hermgrid2d, hermval3d10961097Notes1098-----10991100.. versionadded:: 1.7.011011102"""1103return pu._gridnd(hermval, c, x, y, z)110411051106def hermvander(x, deg):1107"""Pseudo-Vandermonde matrix of given degree.11081109Returns the pseudo-Vandermonde matrix of degree `deg` and sample points1110`x`. The pseudo-Vandermonde matrix is defined by11111112.. math:: V[..., i] = H_i(x),11131114where `0 <= i <= deg`. The leading indices of `V` index the elements of1115`x` and the last index is the degree of the Hermite polynomial.11161117If `c` is a 1-D array of coefficients of length `n + 1` and `V` is the1118array ``V = hermvander(x, n)``, then ``np.dot(V, c)`` and1119``hermval(x, c)`` are the same up to roundoff. This equivalence is1120useful both for least squares fitting and for the evaluation of a large1121number of Hermite series of the same degree and sample points.11221123Parameters1124----------1125x : array_like1126Array of points. The dtype is converted to float64 or complex1281127depending on whether any of the elements are complex. If `x` is1128scalar it is converted to a 1-D array.1129deg : int1130Degree of the resulting matrix.11311132Returns1133-------1134vander : ndarray1135The pseudo-Vandermonde matrix. The shape of the returned matrix is1136``x.shape + (deg + 1,)``, where The last index is the degree of the1137corresponding Hermite polynomial. The dtype will be the same as1138the converted `x`.11391140Examples1141--------1142>>> from numpy.polynomial.hermite import hermvander1143>>> x = np.array([-1, 0, 1])1144>>> hermvander(x, 3)1145array([[ 1., -2., 2., 4.],1146[ 1., 0., -2., -0.],1147[ 1., 2., 2., -4.]])11481149"""1150ideg = pu._deprecate_as_int(deg, "deg")1151if ideg < 0:1152raise ValueError("deg must be non-negative")11531154x = np.array(x, copy=False, ndmin=1) + 0.01155dims = (ideg + 1,) + x.shape1156dtyp = x.dtype1157v = np.empty(dims, dtype=dtyp)1158v[0] = x*0 + 11159if ideg > 0:1160x2 = x*21161v[1] = x21162for i in range(2, ideg + 1):1163v[i] = (v[i-1]*x2 - v[i-2]*(2*(i - 1)))1164return np.moveaxis(v, 0, -1)116511661167def hermvander2d(x, y, deg):1168"""Pseudo-Vandermonde matrix of given degrees.11691170Returns the pseudo-Vandermonde matrix of degrees `deg` and sample1171points `(x, y)`. The pseudo-Vandermonde matrix is defined by11721173.. math:: V[..., (deg[1] + 1)*i + j] = H_i(x) * H_j(y),11741175where `0 <= i <= deg[0]` and `0 <= j <= deg[1]`. The leading indices of1176`V` index the points `(x, y)` and the last index encodes the degrees of1177the Hermite polynomials.11781179If ``V = hermvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`1180correspond to the elements of a 2-D coefficient array `c` of shape1181(xdeg + 1, ydeg + 1) in the order11821183.. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...11841185and ``np.dot(V, c.flat)`` and ``hermval2d(x, y, c)`` will be the same1186up to roundoff. This equivalence is useful both for least squares1187fitting and for the evaluation of a large number of 2-D Hermite1188series of the same degrees and sample points.11891190Parameters1191----------1192x, y : array_like1193Arrays of point coordinates, all of the same shape. The dtypes1194will be converted to either float64 or complex128 depending on1195whether any of the elements are complex. Scalars are converted to 1-D1196arrays.1197deg : list of ints1198List of maximum degrees of the form [x_deg, y_deg].11991200Returns1201-------1202vander2d : ndarray1203The shape of the returned matrix is ``x.shape + (order,)``, where1204:math:`order = (deg[0]+1)*(deg[1]+1)`. The dtype will be the same1205as the converted `x` and `y`.12061207See Also1208--------1209hermvander, hermvander3d, hermval2d, hermval3d12101211Notes1212-----12131214.. versionadded:: 1.7.012151216"""1217return pu._vander_nd_flat((hermvander, hermvander), (x, y), deg)121812191220def hermvander3d(x, y, z, deg):1221"""Pseudo-Vandermonde matrix of given degrees.12221223Returns the pseudo-Vandermonde matrix of degrees `deg` and sample1224points `(x, y, z)`. If `l, m, n` are the given degrees in `x, y, z`,1225then The pseudo-Vandermonde matrix is defined by12261227.. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = H_i(x)*H_j(y)*H_k(z),12281229where `0 <= i <= l`, `0 <= j <= m`, and `0 <= j <= n`. The leading1230indices of `V` index the points `(x, y, z)` and the last index encodes1231the degrees of the Hermite polynomials.12321233If ``V = hermvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns1234of `V` correspond to the elements of a 3-D coefficient array `c` of1235shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order12361237.. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...12381239and ``np.dot(V, c.flat)`` and ``hermval3d(x, y, z, c)`` will be the1240same up to roundoff. This equivalence is useful both for least squares1241fitting and for the evaluation of a large number of 3-D Hermite1242series of the same degrees and sample points.12431244Parameters1245----------1246x, y, z : array_like1247Arrays of point coordinates, all of the same shape. The dtypes will1248be converted to either float64 or complex128 depending on whether1249any of the elements are complex. Scalars are converted to 1-D1250arrays.1251deg : list of ints1252List of maximum degrees of the form [x_deg, y_deg, z_deg].12531254Returns1255-------1256vander3d : ndarray1257The shape of the returned matrix is ``x.shape + (order,)``, where1258:math:`order = (deg[0]+1)*(deg[1]+1)*(deg[2]+1)`. The dtype will1259be the same as the converted `x`, `y`, and `z`.12601261See Also1262--------1263hermvander, hermvander3d, hermval2d, hermval3d12641265Notes1266-----12671268.. versionadded:: 1.7.012691270"""1271return pu._vander_nd_flat((hermvander, hermvander, hermvander), (x, y, z), deg)127212731274def hermfit(x, y, deg, rcond=None, full=False, w=None):1275"""1276Least squares fit of Hermite series to data.12771278Return the coefficients of a Hermite series of degree `deg` that is the1279least squares fit to the data values `y` given at points `x`. If `y` is12801-D the returned coefficients will also be 1-D. If `y` is 2-D multiple1281fits are done, one for each column of `y`, and the resulting1282coefficients are stored in the corresponding columns of a 2-D return.1283The fitted polynomial(s) are in the form12841285.. math:: p(x) = c_0 + c_1 * H_1(x) + ... + c_n * H_n(x),12861287where `n` is `deg`.12881289Parameters1290----------1291x : array_like, shape (M,)1292x-coordinates of the M sample points ``(x[i], y[i])``.1293y : array_like, shape (M,) or (M, K)1294y-coordinates of the sample points. Several data sets of sample1295points sharing the same x-coordinates can be fitted at once by1296passing in a 2D-array that contains one dataset per column.1297deg : int or 1-D array_like1298Degree(s) of the fitting polynomials. If `deg` is a single integer1299all terms up to and including the `deg`'th term are included in the1300fit. For NumPy versions >= 1.11.0 a list of integers specifying the1301degrees of the terms to include may be used instead.1302rcond : float, optional1303Relative condition number of the fit. Singular values smaller than1304this relative to the largest singular value will be ignored. The1305default value is len(x)*eps, where eps is the relative precision of1306the float type, about 2e-16 in most cases.1307full : bool, optional1308Switch determining nature of return value. When it is False (the1309default) just the coefficients are returned, when True diagnostic1310information from the singular value decomposition is also returned.1311w : array_like, shape (`M`,), optional1312Weights. If not None, the weight ``w[i]`` applies to the unsquared1313residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are1314chosen so that the errors of the products ``w[i]*y[i]`` all have the1315same variance. When using inverse-variance weighting, use1316``w[i] = 1/sigma(y[i])``. The default value is None.13171318Returns1319-------1320coef : ndarray, shape (M,) or (M, K)1321Hermite coefficients ordered from low to high. If `y` was 2-D,1322the coefficients for the data in column k of `y` are in column1323`k`.13241325[residuals, rank, singular_values, rcond] : list1326These values are only returned if ``full == True``13271328- residuals -- sum of squared residuals of the least squares fit1329- rank -- the numerical rank of the scaled Vandermonde matrix1330- singular_values -- singular values of the scaled Vandermonde matrix1331- rcond -- value of `rcond`.13321333For more details, see `numpy.linalg.lstsq`.13341335Warns1336-----1337RankWarning1338The rank of the coefficient matrix in the least-squares fit is1339deficient. The warning is only raised if ``full == False``. The1340warnings can be turned off by13411342>>> import warnings1343>>> warnings.simplefilter('ignore', np.RankWarning)13441345See Also1346--------1347numpy.polynomial.chebyshev.chebfit1348numpy.polynomial.legendre.legfit1349numpy.polynomial.laguerre.lagfit1350numpy.polynomial.polynomial.polyfit1351numpy.polynomial.hermite_e.hermefit1352hermval : Evaluates a Hermite series.1353hermvander : Vandermonde matrix of Hermite series.1354hermweight : Hermite weight function1355numpy.linalg.lstsq : Computes a least-squares fit from the matrix.1356scipy.interpolate.UnivariateSpline : Computes spline fits.13571358Notes1359-----1360The solution is the coefficients of the Hermite series `p` that1361minimizes the sum of the weighted squared errors13621363.. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,13641365where the :math:`w_j` are the weights. This problem is solved by1366setting up the (typically) overdetermined matrix equation13671368.. math:: V(x) * c = w * y,13691370where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the1371coefficients to be solved for, `w` are the weights, `y` are the1372observed values. This equation is then solved using the singular value1373decomposition of `V`.13741375If some of the singular values of `V` are so small that they are1376neglected, then a `RankWarning` will be issued. This means that the1377coefficient values may be poorly determined. Using a lower order fit1378will usually get rid of the warning. The `rcond` parameter can also be1379set to a value smaller than its default, but the resulting fit may be1380spurious and have large contributions from roundoff error.13811382Fits using Hermite series are probably most useful when the data can be1383approximated by ``sqrt(w(x)) * p(x)``, where `w(x)` is the Hermite1384weight. In that case the weight ``sqrt(w(x[i]))`` should be used1385together with data values ``y[i]/sqrt(w(x[i]))``. The weight function is1386available as `hermweight`.13871388References1389----------1390.. [1] Wikipedia, "Curve fitting",1391https://en.wikipedia.org/wiki/Curve_fitting13921393Examples1394--------1395>>> from numpy.polynomial.hermite import hermfit, hermval1396>>> x = np.linspace(-10, 10)1397>>> err = np.random.randn(len(x))/101398>>> y = hermval(x, [1, 2, 3]) + err1399>>> hermfit(x, y, 2)1400array([1.0218, 1.9986, 2.9999]) # may vary14011402"""1403return pu._fit(hermvander, x, y, deg, rcond, full, w)140414051406def hermcompanion(c):1407"""Return the scaled companion matrix of c.14081409The basis polynomials are scaled so that the companion matrix is1410symmetric when `c` is an Hermite basis polynomial. This provides1411better eigenvalue estimates than the unscaled case and for basis1412polynomials the eigenvalues are guaranteed to be real if1413`numpy.linalg.eigvalsh` is used to obtain them.14141415Parameters1416----------1417c : array_like14181-D array of Hermite series coefficients ordered from low to high1419degree.14201421Returns1422-------1423mat : ndarray1424Scaled companion matrix of dimensions (deg, deg).14251426Notes1427-----14281429.. versionadded:: 1.7.014301431"""1432# c is a trimmed copy1433[c] = pu.as_series([c])1434if len(c) < 2:1435raise ValueError('Series must have maximum degree of at least 1.')1436if len(c) == 2:1437return np.array([[-.5*c[0]/c[1]]])14381439n = len(c) - 11440mat = np.zeros((n, n), dtype=c.dtype)1441scl = np.hstack((1., 1./np.sqrt(2.*np.arange(n - 1, 0, -1))))1442scl = np.multiply.accumulate(scl)[::-1]1443top = mat.reshape(-1)[1::n+1]1444bot = mat.reshape(-1)[n::n+1]1445top[...] = np.sqrt(.5*np.arange(1, n))1446bot[...] = top1447mat[:, -1] -= scl*c[:-1]/(2.0*c[-1])1448return mat144914501451def hermroots(c):1452"""1453Compute the roots of a Hermite series.14541455Return the roots (a.k.a. "zeros") of the polynomial14561457.. math:: p(x) = \\sum_i c[i] * H_i(x).14581459Parameters1460----------1461c : 1-D array_like14621-D array of coefficients.14631464Returns1465-------1466out : ndarray1467Array of the roots of the series. If all the roots are real,1468then `out` is also real, otherwise it is complex.14691470See Also1471--------1472numpy.polynomial.polynomial.polyroots1473numpy.polynomial.legendre.legroots1474numpy.polynomial.laguerre.lagroots1475numpy.polynomial.chebyshev.chebroots1476numpy.polynomial.hermite_e.hermeroots14771478Notes1479-----1480The root estimates are obtained as the eigenvalues of the companion1481matrix, Roots far from the origin of the complex plane may have large1482errors due to the numerical instability of the series for such1483values. Roots with multiplicity greater than 1 will also show larger1484errors as the value of the series near such points is relatively1485insensitive to errors in the roots. Isolated roots near the origin can1486be improved by a few iterations of Newton's method.14871488The Hermite series basis polynomials aren't powers of `x` so the1489results of this function may seem unintuitive.14901491Examples1492--------1493>>> from numpy.polynomial.hermite import hermroots, hermfromroots1494>>> coef = hermfromroots([-1, 0, 1])1495>>> coef1496array([0. , 0.25 , 0. , 0.125])1497>>> hermroots(coef)1498array([-1.00000000e+00, -1.38777878e-17, 1.00000000e+00])14991500"""1501# c is a trimmed copy1502[c] = pu.as_series([c])1503if len(c) <= 1:1504return np.array([], dtype=c.dtype)1505if len(c) == 2:1506return np.array([-.5*c[0]/c[1]])15071508# rotated companion matrix reduces error1509m = hermcompanion(c)[::-1,::-1]1510r = la.eigvals(m)1511r.sort()1512return r151315141515def _normed_hermite_n(x, n):1516"""1517Evaluate a normalized Hermite polynomial.15181519Compute the value of the normalized Hermite polynomial of degree ``n``1520at the points ``x``.152115221523Parameters1524----------1525x : ndarray of double.1526Points at which to evaluate the function1527n : int1528Degree of the normalized Hermite function to be evaluated.15291530Returns1531-------1532values : ndarray1533The shape of the return value is described above.15341535Notes1536-----1537.. versionadded:: 1.10.015381539This function is needed for finding the Gauss points and integration1540weights for high degrees. The values of the standard Hermite functions1541overflow when n >= 207.15421543"""1544if n == 0:1545return np.full(x.shape, 1/np.sqrt(np.sqrt(np.pi)))15461547c0 = 0.1548c1 = 1./np.sqrt(np.sqrt(np.pi))1549nd = float(n)1550for i in range(n - 1):1551tmp = c01552c0 = -c1*np.sqrt((nd - 1.)/nd)1553c1 = tmp + c1*x*np.sqrt(2./nd)1554nd = nd - 1.01555return c0 + c1*x*np.sqrt(2)155615571558def hermgauss(deg):1559"""1560Gauss-Hermite quadrature.15611562Computes the sample points and weights for Gauss-Hermite quadrature.1563These sample points and weights will correctly integrate polynomials of1564degree :math:`2*deg - 1` or less over the interval :math:`[-\\inf, \\inf]`1565with the weight function :math:`f(x) = \\exp(-x^2)`.15661567Parameters1568----------1569deg : int1570Number of sample points and weights. It must be >= 1.15711572Returns1573-------1574x : ndarray15751-D ndarray containing the sample points.1576y : ndarray15771-D ndarray containing the weights.15781579Notes1580-----15811582.. versionadded:: 1.7.015831584The results have only been tested up to degree 100, higher degrees may1585be problematic. The weights are determined by using the fact that15861587.. math:: w_k = c / (H'_n(x_k) * H_{n-1}(x_k))15881589where :math:`c` is a constant independent of :math:`k` and :math:`x_k`1590is the k'th root of :math:`H_n`, and then scaling the results to get1591the right value when integrating 1.15921593"""1594ideg = pu._deprecate_as_int(deg, "deg")1595if ideg <= 0:1596raise ValueError("deg must be a positive integer")15971598# first approximation of roots. We use the fact that the companion1599# matrix is symmetric in this case in order to obtain better zeros.1600c = np.array([0]*deg + [1], dtype=np.float64)1601m = hermcompanion(c)1602x = la.eigvalsh(m)16031604# improve roots by one application of Newton1605dy = _normed_hermite_n(x, ideg)1606df = _normed_hermite_n(x, ideg - 1) * np.sqrt(2*ideg)1607x -= dy/df16081609# compute the weights. We scale the factor to avoid possible numerical1610# overflow.1611fm = _normed_hermite_n(x, ideg - 1)1612fm /= np.abs(fm).max()1613w = 1/(fm * fm)16141615# for Hermite we can also symmetrize1616w = (w + w[::-1])/21617x = (x - x[::-1])/216181619# scale w to get the right value1620w *= np.sqrt(np.pi) / w.sum()16211622return x, w162316241625def hermweight(x):1626"""1627Weight function of the Hermite polynomials.16281629The weight function is :math:`\\exp(-x^2)` and the interval of1630integration is :math:`[-\\inf, \\inf]`. the Hermite polynomials are1631orthogonal, but not normalized, with respect to this weight function.16321633Parameters1634----------1635x : array_like1636Values at which the weight function will be computed.16371638Returns1639-------1640w : ndarray1641The weight function at `x`.16421643Notes1644-----16451646.. versionadded:: 1.7.016471648"""1649w = np.exp(-x**2)1650return w165116521653#1654# Hermite series class1655#16561657class Hermite(ABCPolyBase):1658"""An Hermite series class.16591660The Hermite class provides the standard Python numerical methods1661'+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the1662attributes and methods listed in the `ABCPolyBase` documentation.16631664Parameters1665----------1666coef : array_like1667Hermite coefficients in order of increasing degree, i.e,1668``(1, 2, 3)`` gives ``1*H_0(x) + 2*H_1(X) + 3*H_2(x)``.1669domain : (2,) array_like, optional1670Domain to use. The interval ``[domain[0], domain[1]]`` is mapped1671to the interval ``[window[0], window[1]]`` by shifting and scaling.1672The default value is [-1, 1].1673window : (2,) array_like, optional1674Window, see `domain` for its use. The default value is [-1, 1].16751676.. versionadded:: 1.6.016771678"""1679# Virtual Functions1680_add = staticmethod(hermadd)1681_sub = staticmethod(hermsub)1682_mul = staticmethod(hermmul)1683_div = staticmethod(hermdiv)1684_pow = staticmethod(hermpow)1685_val = staticmethod(hermval)1686_int = staticmethod(hermint)1687_der = staticmethod(hermder)1688_fit = staticmethod(hermfit)1689_line = staticmethod(hermline)1690_roots = staticmethod(hermroots)1691_fromroots = staticmethod(hermfromroots)16921693# Virtual properties1694domain = np.array(hermdomain)1695window = np.array(hermdomain)1696basis_name = 'H'169716981699