Cyforanumera
npm

API reference

np.polynomial (series classes)

Power, Chebyshev, Legendre, Laguerre, Hermite and HermiteE series: classes with domain/window mapping, plus the per-basis module functions.

NameSummary
np.polynomial.PolynomialSeries classes of numpy.polynomial.
np.polynomial.Polynomial.fitClass factories.
np.polynomial.chebyshevModule functions on raw coefficient arrays.
np.polynomial.setDefaultPrintstyleSwitches toString() of all series between unicode and ascii output.

np.polynomial.Polynomial

#
new np.polynomial.Polynomial(coef, domain?, window?, symbol = "x") · Chebyshev · Legendre · Laguerre · Hermite · HermiteE

Series classes of numpy.polynomial. Coefficients run from lowest degree to highest and are stored as float64 (or complex128). domain is mapped linearly onto window before the series is evaluated. Python operators become methods: add, sub, rsub, mul, truediv, floordiv, mod, divmod, pow, neg, equals. toString() is Python's str() and repr() is repr().

Parameters

coefArrayLike
Series coefficients, lowest degree first.

Returns

series instance

Example

TypeScript
const p = new np.polynomial.Polynomial([1, 2, 3]);
p.call([0, 1, 2]);                         // => [1, 6, 17]
String(p);                                 // => "1.0 + 2.0·x + 3.0·x²"
p.mul([1, 1]).coef;                        // => [1, 3, 5, 3]
p.pow(2).coef;                             // => [1, 4, 10, 12, 9]
p.divmod([1, 1]).map((q) => q.coef.toArray()); // => [[-1, 3], [2]]
p.deriv().coef;                            // => [2, 6]
p.integ().coef;                            // => [0, 1, 1, 1]
new np.polynomial.Chebyshev([1, 2, 3]).convert(null, np.polynomial.Polynomial).coef; // => [-2, 2, 6]
new np.polynomial.Polynomial([1, 2]).repr(); // => "Polynomial([1., 2.], domain=[-1.,  1.], window=[-1.,  1.], symbol='x')"

np.polynomial.Polynomial.fit

#
Cls.fit(x, y, deg, { domain, window, rcond, w, symbol }) · Cls.fitFull(...) · Cls.fromroots(roots, opts) · Cls.identity(domain?, window?) · Cls.basis(deg, opts) · Cls.cast(series)

Class factories. fit computes a least-squares fit, with the domain defaulting to the range of x; .convert() maps the result back to the default domain. p.roots() returns the eigenvalues of the companion matrix, mapped into the domain.

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
yArrayLike
An NDArray, nested JS array or scalar.
degnumber | number[]
Degree, or the list of degrees to include.

Returns

series instance

Example

TypeScript
const f = np.polynomial.Polynomial.fit([0, 1, 2, 3], [1, 3, 5, 7], 1);
f.domain;                                   // => [0, 3]
f.convert().coef;                           // => [1, 2]
np.polynomial.Polynomial.fromroots([1, 2]).coef; // => [2, -3, 1]
np.polynomial.Polynomial.fromroots([1, 2]).roots(); // => [1, 2]
np.polynomial.Laguerre.basis(2).coef;       // => [0, 0, 1]

np.polynomial.chebyshev

#
np.polynomial.{polynomial, chebyshev, legendre, laguerre, hermite, hermite_e}.<prefix>{add, sub, mul, mulx, div, pow, val, der, int, vander, companion, fromroots, roots, fit, trim, line, domain, zero, one, x} · cheb2poly / poly2cheb ...

Module functions on raw coefficient arrays. They keep NumPy's prefixed names (poly, cheb, leg, lag, herm, herme). Only 1-D coefficients are supported. <prefix>int takes { m, k, lbnd, scl }.

Parameters

cArrayLike
1-D coefficient array.

Returns

NDArray

Example

TypeScript
np.polynomial.chebyshev.chebval(0.5, [1, 2, 3]); // => 0.5
np.polynomial.polynomial.polydiv([1, 2, 3, 4], [1, 2]).map((a) => a.toArray()); // => [[0.75, 0.5, 2], [0.25]]
np.polynomial.legendre.leg2poly([1, 2, 3]);  // => [-0.5, 2, 4.5]
np.polynomial.hermite.hermvander([0, 1], 2); // => [[1, 0, -2], [1, 2, 2]]
np.polynomial.polynomial.polyroots([2, -3, 1]); // => [1, 2]
TypeScript declaration
np.polynomial.chebyshev: Record<string, unknown>

np.polynomial.setDefaultPrintstyle

#
np.polynomial.setDefaultPrintstyle("unicode" | "ascii")

Switches toString() of all series between unicode and ascii output. p.format("ascii") picks the style for one call.

Parameters

stylestring
"unicode" (default) or "ascii".

Returns

void

Example

TypeScript
new np.polynomial.Chebyshev([1, 2, 3]).format("ascii"); // => "1.0 + 2.0 T_1(x) + 3.0 T_2(x)"