class documentation

class ABCPolyBase(abc.ABC):

Known subclasses: numpy.polynomial.chebyshev.Chebyshev, numpy.polynomial.hermite.Hermite, numpy.polynomial.hermite_e.HermiteE, numpy.polynomial.laguerre.Laguerre, numpy.polynomial.legendre.Legendre, numpy.polynomial.polynomial.Polynomial

View In Hierarchy

An abstract base class for immutable series classes.

ABCPolyBase provides the standard Python numerical methods '+', '-', '*', '//', '%', 'divmod', '**', and '()' along with the methods listed below.

New in version 1.9.0.

Parameters

coef : array_like
Series coefficients in order of increasing degree, i.e., (1, 2, 3) gives 1*P_0(x) + 2*P_1(x) + 3*P_2(x), where P_i is the basis polynomials of degree i.
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 the derived class domain.
window : (2,) array_like, optional
Window, see domain for its use. The default value is the derived class window.

Attributes

coef : (N,) ndarray
Series coefficients in order of increasing degree.
domain : (2,) ndarray
Domain that is mapped to window.
window : (2,) ndarray
Window that domain is mapped to.

Class Attributes

maxpower : int
Maximum power allowed, i.e., the largest number n such that p(x)**n is allowed. This is to limit runaway polynomial size.
domain : (2,) ndarray
Default domain of the class.
window : (2,) ndarray
Default window of the class.
Class Method basis Series basis polynomial of degree deg.
Class Method cast Convert series to series of this class.
Class Method fit Least squares fit to data.
Class Method fromroots Return series instance that has the specified roots.
Class Method identity Identity function.
Class Method ​_repr​_latex​_term Undocumented
Class Method ​_str​_term​_ascii String representation of a single polynomial term using ** and _ to represent superscripts and subscripts, respectively.
Class Method ​_str​_term​_unicode String representation of single polynomial term using unicode characters for superscripts and subscripts.
Static Method ​_add Undocumented
Static Method ​_der Undocumented
Static Method ​_div Undocumented
Static Method ​_fit Undocumented
Static Method ​_fromroots Undocumented
Static Method ​_int Undocumented
Static Method ​_line Undocumented
Static Method ​_mul Undocumented
Static Method ​_pow Undocumented
Static Method ​_repr​_latex​_scalar Undocumented
Static Method ​_roots Undocumented
Static Method ​_sub Undocumented
Static Method ​_val Undocumented
Method __add__ Undocumented
Method __call__ Undocumented
Method __divmod__ Undocumented
Method __eq__ Undocumented
Method __floordiv__ Undocumented
Method __format__ Undocumented
Method __getstate__ Undocumented
Method __init__ Undocumented
Method __iter__ Undocumented
Method __len__ Undocumented
Method __mod__ Undocumented
Method __mul__ Undocumented
Method __ne__ Undocumented
Method __neg__ Undocumented
Method __pos__ Undocumented
Method __pow__ Undocumented
Method __radd__ Undocumented
Method __rdiv__ Undocumented
Method __rdivmod__ Undocumented
Method __repr__ Undocumented
Method __rfloordiv__ Undocumented
Method __rmod__ Undocumented
Method __rmul__ Undocumented
Method __rsub__ Undocumented
Method __rtruediv__ Undocumented
Method __setstate__ Undocumented
Method __str__ Undocumented
Method __sub__ Undocumented
Method __truediv__ Undocumented
Method ​_generate​_string Generate the full string representation of the polynomial, using term_method to generate each polynomial term.
Method ​_get​_coefficients Interpret other as polynomial coefficients.
Method ​_repr​_latex​_ Undocumented
Method convert Convert series to a different kind and/or domain and/or window.
Method copy Return a copy.
Method cutdeg Truncate series to the given degree.
Method degree The degree of the series.
Method deriv Differentiate.
Method has​_samecoef Check if coefficients match.
Method has​_samedomain Check if domains match.
Method has​_sametype Check if types match.
Method has​_samewindow Check if windows match.
Method integ Integrate.
Method linspace Return x, y values at equally spaced points in domain.
Method mapparms Return the mapping parameters.
Method roots Return the roots of the series polynomial.
Method trim Remove trailing coefficients
Method truncate Truncate series to length size.
Class Variable __array​_ufunc__ Undocumented
Class Variable __hash__ Undocumented
Class Variable ​_subscript​_mapping Undocumented
Class Variable ​_superscript​_mapping Undocumented
Class Variable ​_use​_unicode Undocumented
Class Variable maxpower Undocumented
Instance Variable __dict__ Undocumented
Instance Variable coef Undocumented
Instance Variable domain Undocumented
Instance Variable window Undocumented
Property basis​_name Undocumented
@classmethod
def basis(cls, deg, domain=None, window=None):

Series basis polynomial of degree deg.

Returns the series representing the basis polynomial of degree deg.

New in version 1.7.0.

Parameters

deg : int
Degree of the basis polynomial for the series. Must be >= 0.
domain : {None, array_like}, optional
If given, the array must be of the form [beg, end], where beg and end are the endpoints of the domain. If None is given then the class domain is used. The default is None.
window : {None, array_like}, optional
If given, the resulting array must be if the form [beg, end], where beg and end are the endpoints of the window. If None is given then the class window is used. The default is None.

Returns

new_series : series
A series with the coefficient of the deg term set to one and all others zero.
@classmethod
def cast(cls, series, domain=None, window=None):

Convert series to series of this class.

The series is expected to be an instance of some polynomial series of one of the types supported by by the numpy.polynomial module, but could be some other class that supports the convert method.

New in version 1.7.0.

Parameters

series : series
The series instance to be converted.
domain : {None, array_like}, optional
If given, the array must be of the form [beg, end], where beg and end are the endpoints of the domain. If None is given then the class domain is used. The default is None.
window : {None, array_like}, optional
If given, the resulting array must be if the form [beg, end], where beg and end are the endpoints of the window. If None is given then the class window is used. The default is None.

Returns

new_series : series
A series of the same kind as the calling class and equal to series when evaluated.

See Also

convert : similar instance method

@classmethod
def fit(cls, x, y, deg, domain=None, rcond=None, full=False, w=None, window=None):

Least squares fit to data.

Return a series instance that is the least squares fit to the data y sampled at x. The domain of the returned instance can be specified and this will often result in a superior fit with less chance of ill conditioning.

Parameters

x : array_like, shape (M,)
x-coordinates of the M sample points (x[i], y[i]).
y : array_like, shape (M,)
y-coordinates of the M sample points (x[i], y[i]).
deg : int or 1-D array_like
Degree(s) of the fitting polynomials. If deg is a single integer all terms up to and including the deg'th term are included in the fit. For NumPy versions >= 1.11.0 a list of integers specifying the degrees of the terms to include may be used instead.
domain : {None, [beg, end], []}, optional
Domain to use for the returned series. If None, then a minimal domain that covers the points x is chosen. If [] the class domain is used. The default value was the class domain in NumPy 1.4 and None in later versions. The [] option was added in numpy 1.5.0.
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 weight w[i] applies to the unsquared residual y[i] - y_hat[i] at x[i]. Ideally the weights are chosen so that the errors of the products w[i]*y[i] all have the same variance. When using inverse-variance weighting, use w[i] = 1/sigma(y[i]). The default value is None.

New in version 1.5.0.
window : {[beg, end]}, optional

Window to use for the returned series. The default value is the default class domain

New in version 1.6.0.

Returns

new_series : series
A series that represents the least squares fit to the data and has the domain and window specified in the call. If the coefficients for the unscaled and unshifted basis polynomials are of interest, do new_series.convert().coef.
[resid, rank, sv, 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.

@classmethod
def fromroots(cls, roots, domain=[], window=None):

Return series instance that has the specified roots.

Returns a series representing the product (x - r[0])*(x - r[1])*...*(x - r[n-1]), where r is a list of roots.

Parameters

roots : array_like
List of roots.
domain : {[], None, array_like}, optional
Domain for the resulting series. If None the domain is the interval from the smallest root to the largest. If [] the domain is the class domain. The default is [].
window : {None, array_like}, optional
Window for the returned series. If None the class window is used. The default is None.

Returns

new_series : series
Series with the specified roots.
@classmethod
def identity(cls, domain=None, window=None):

Identity function.

If p is the returned series, then p(x) == x for all values of x.

Parameters

domain : {None, array_like}, optional
If given, the array must be of the form [beg, end], where beg and end are the endpoints of the domain. If None is given then the class domain is used. The default is None.
window : {None, array_like}, optional
If given, the resulting array must be if the form [beg, end], where beg and end are the endpoints of the window. If None is given then the class window is used. The default is None.

Returns

new_series : series
Series of representing the identity.
@classmethod
def _repr_latex_term(cls, i, arg_str, needs_parens):

Undocumented

@classmethod
def _str_term_ascii(cls, i, arg_str):
String representation of a single polynomial term using ** and _ to represent superscripts and subscripts, respectively.
@classmethod
def _str_term_unicode(cls, i, arg_str):
String representation of single polynomial term using unicode characters for superscripts and subscripts.
@staticmethod
@abc.abstractmethod
def _add(c1, c2):

Undocumented

@staticmethod
@abc.abstractmethod
def _der(c, m, scl):

Undocumented

@staticmethod
@abc.abstractmethod
def _div(c1, c2):

Undocumented

@staticmethod
@abc.abstractmethod
def _fit(x, y, deg, rcond, full):

Undocumented

@staticmethod
@abc.abstractmethod
def _fromroots(r):

Undocumented

@staticmethod
@abc.abstractmethod
def _int(c, m, k, lbnd, scl):

Undocumented

@staticmethod
@abc.abstractmethod
def _line(off, scl):

Undocumented

@staticmethod
@abc.abstractmethod
def _mul(c1, c2):

Undocumented

@staticmethod
@abc.abstractmethod
def _pow(c, pow, maxpower=None):

Undocumented

@staticmethod
def _repr_latex_scalar(x):

Undocumented

@staticmethod
@abc.abstractmethod
def _roots(c):

Undocumented

@staticmethod
@abc.abstractmethod
def _sub(c1, c2):

Undocumented

@staticmethod
@abc.abstractmethod
def _val(x, c):

Undocumented

def __add__(self, other):

Undocumented

def __call__(self, arg):

Undocumented

def __divmod__(self, other):

Undocumented

def __eq__(self, other):

Undocumented

def __floordiv__(self, other):

Undocumented

def __format__(self, fmt_str):

Undocumented

def __getstate__(self):

Undocumented

def __init__(self, coef, domain=None, window=None):

Undocumented

def __iter__(self):

Undocumented

def __len__(self):

Undocumented

def __mod__(self, other):

Undocumented

def __mul__(self, other):

Undocumented

def __ne__(self, other):

Undocumented

def __neg__(self):

Undocumented

def __pos__(self):

Undocumented

def __pow__(self, other):

Undocumented

def __radd__(self, other):

Undocumented

def __rdiv__(self, other):

Undocumented

def __rdivmod__(self, other):

Undocumented

def __repr__(self):

Undocumented

def __rfloordiv__(self, other):

Undocumented

def __rmod__(self, other):

Undocumented

def __rmul__(self, other):

Undocumented

def __rsub__(self, other):

Undocumented

def __rtruediv__(self, other):

Undocumented

def __setstate__(self, dict):

Undocumented

def __str__(self):

Undocumented

def __sub__(self, other):

Undocumented

def __truediv__(self, other):

Undocumented

def _generate_string(self, term_method):
Generate the full string representation of the polynomial, using term_method to generate each polynomial term.
def _get_coefficients(self, other):

Interpret other as polynomial coefficients.

The other argument is checked to see if it is of the same class as self with identical domain and window. If so, return its coefficients, otherwise return other.

New in version 1.9.0.

Parameters

other : anything
Object to be checked.

Returns

coef
The coefficients of`other` if it is a compatible instance, of ABCPolyBase, otherwise other.

Raises

TypeError
When other is an incompatible instance of ABCPolyBase.
def _repr_latex_(self):

Undocumented

def convert(self, domain=None, kind=None, window=None):

Convert series to a different kind and/or domain and/or window.

Parameters

domain : array_like, optional
The domain of the converted series. If the value is None, the default domain of kind is used.
kind : class, optional
The polynomial series type class to which the current instance should be converted. If kind is None, then the class of the current instance is used.
window : array_like, optional
The window of the converted series. If the value is None, the default window of kind is used.

Returns

new_series : series
The returned class can be of different type than the current instance and/or have a different domain and/or different window.

Notes

Conversion between domains and class types can result in numerically ill defined series.

def copy(self):

Return a copy.

Returns

new_series : series
Copy of self.
def cutdeg(self, deg):

Truncate series to the given degree.

Reduce the degree of the series to deg by discarding the high order terms. If deg is greater than the current degree a copy of the current series is returned. This can be useful in least squares where the coefficients of the high degree terms may be very small.

New in version 1.5.0.

Parameters

deg : non-negative int
The series is reduced to degree deg by discarding the high order terms. The value of deg must be a non-negative integer.

Returns

new_series : series
New instance of series with reduced degree.
def degree(self):

The degree of the series.

New in version 1.5.0.

Returns

degree : int
Degree of the series, one less than the number of coefficients.
def deriv(self, m=1):

Differentiate.

Return a series instance of that is the derivative of the current series.

Parameters

m : non-negative int
Find the derivative of order m.

Returns

new_series : series
A new series representing the derivative. The domain is the same as the domain of the differentiated series.
def has_samecoef(self, other):

Check if coefficients match.

New in version 1.6.0.

Parameters

other : class instance
The other class must have the coef attribute.

Returns

bool : boolean
True if the coefficients are the same, False otherwise.
def has_samedomain(self, other):

Check if domains match.

New in version 1.6.0.

Parameters

other : class instance
The other class must have the domain attribute.

Returns

bool : boolean
True if the domains are the same, False otherwise.
def has_sametype(self, other):

Check if types match.

New in version 1.7.0.

Parameters

other : object
Class instance.

Returns

bool : boolean
True if other is same class as self
def has_samewindow(self, other):

Check if windows match.

New in version 1.6.0.

Parameters

other : class instance
The other class must have the window attribute.

Returns

bool : boolean
True if the windows are the same, False otherwise.
def integ(self, m=1, k=[], lbnd=None):

Integrate.

Return a series instance that is the definite integral of the current series.

Parameters

m : non-negative int
The number of integrations to perform.
k : array_like
Integration constants. The first constant is applied to the first integration, the second to the second, and so on. The list of values must less than or equal to m in length and any missing values are set to zero.
lbnd : Scalar
The lower bound of the definite integral.

Returns

new_series : series
A new series representing the integral. The domain is the same as the domain of the integrated series.
def linspace(self, n=100, domain=None):

Return x, y values at equally spaced points in domain.

Returns the x, y values at n linearly spaced points across the domain. Here y is the value of the polynomial at the points x. By default the domain is the same as that of the series instance. This method is intended mostly as a plotting aid.

New in version 1.5.0.

Parameters

n : int, optional
Number of point pairs to return. The default value is 100.
domain : {None, array_like}, optional
If not None, the specified domain is used instead of that of the calling instance. It should be of the form [beg,end]. The default is None which case the class domain is used.

Returns

x, y : ndarray
x is equal to linspace(self.domain[0], self.domain[1], n) and y is the series evaluated at element of x.
def mapparms(self):

Return the mapping parameters.

The returned values define a linear map off + scl*x that is applied to the input arguments before the series is evaluated. The map depends on the domain and window; if the current domain is equal to the window the resulting map is the identity. If the coefficients of the series instance are to be used by themselves outside this class, then the linear function must be substituted for the x in the standard representation of the base polynomials.

Returns

off, scl : float or complex
The mapping function is defined by off + scl*x.

Notes

If the current domain is the interval [l1, r1] and the window is [l2, r2], then the linear mapping function L is defined by the equations:

L(l1) = l2
L(r1) = r2
def roots(self):

Return the roots of the series polynomial.

Compute the roots for the series. Note that the accuracy of the roots decrease the further outside the domain they lie.

Returns

roots : ndarray
Array containing the roots of the series.
def trim(self, tol=0):

Remove trailing coefficients

Remove trailing coefficients until a coefficient is reached whose absolute value greater than tol or the beginning of the series is reached. If all the coefficients would be removed the series is set to [0]. A new series instance is returned with the new coefficients. The current instance remains unchanged.

Parameters

tol : non-negative number.
All trailing coefficients less than tol will be removed.

Returns

new_series : series
New instance of series with trimmed coefficients.
def truncate(self, size):

Truncate series to length size.

Reduce the series to length size by discarding the high degree terms. The value of size must be a positive integer. This can be useful in least squares where the coefficients of the high degree terms may be very small.

Parameters

size : positive int
The series is reduced to length size by discarding the high degree terms. The value of size must be a positive integer.

Returns

new_series : series
New instance of series with truncated coefficients.
__array_ufunc__ =

Undocumented

__hash__ =

Undocumented

_subscript_mapping =

Undocumented

_superscript_mapping =

Undocumented

_use_unicode =

Undocumented

maxpower: int =

Undocumented

__dict__ =

Undocumented

coef =

Undocumented