MCPcopy Create free account
hub / github.com/numpy/numpy / herm2poly

Function herm2poly

numpy/polynomial/hermite.py:142–197  ·  view source on GitHub ↗

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 de

(c)

Source from the content-addressed store, hash-verified

140
141
142def herm2poly(c):
143 """
144 Convert a Hermite series to a polynomial.
145
146 Convert an array representing the coefficients of a Hermite series,
147 ordered from lowest degree to highest, to an array of the coefficients
148 of the equivalent polynomial (relative to the "standard" basis) ordered
149 from lowest to highest degree.
150
151 Parameters
152 ----------
153 c : array_like
154 1-D array containing the Hermite series coefficients, ordered
155 from lowest order term to highest.
156
157 Returns
158 -------
159 pol : ndarray
160 1-D array containing the coefficients of the equivalent polynomial
161 (relative to the "standard" basis) ordered from lowest order term
162 to highest.
163
164 See Also
165 --------
166 poly2herm
167
168 Notes
169 -----
170 The easy way to do conversions between polynomial basis sets
171 is to use the convert method of a class instance.
172
173 Examples
174 --------
175 >>> from numpy.polynomial.hermite import herm2poly
176 >>> herm2poly([ 1. , 2.75 , 0.5 , 0.375])
177 array([0., 1., 2., 3.])
178
179 """
180 from .polynomial import polyadd, polysub, polymulx
181
182 [c] = pu.as_series([c])
183 n = len(c)
184 if n == 1:
185 return c
186 if n == 2:
187 c[1] *= 2
188 return c
189 else:
190 c0 = c[-2]
191 c1 = c[-1]
192 # i is the current degree of c1
193 for i in range(n - 1, 1, -1):
194 tmp = c0
195 c0 = polysub(c[i - 2], c1*(2*(i - 1)))
196 c1 = polyadd(tmp, polymulx(c1)*2)
197 return polyadd(c0, polymulx(c1)*2)
198
199#

Callers

nothing calls this directly

Calls 3

polymulxFunction · 0.85
polysubFunction · 0.70
polyaddFunction · 0.70

Tested by

no test coverage detected