class documentation

An abstract base class for immutable series classes. ABCPolyBase provides the standard Python numerical methods '+', '-', '*', '//', '%', 'divmod', '**', and '()' along with the methods listed below. .. versionadded:: 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. symbol : str, optional Symbol used to represent the independent variable in string representations of the polynomial expression, e.g. for printing. The symbol must be a valid Python identifier. Default value is 'x'. .. versionadded:: 1.24 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. symbol : str Symbol representing the independent variable. 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.
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 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 maxpower Undocumented
Instance Variable __dict__ Undocumented
Instance Variable coef Undocumented
Instance Variable domain Undocumented
Instance Variable window Undocumented
Property basis_name Undocumented
Property symbol Undocumented
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 _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
Class Variable _subscript_mapping Undocumented
Class Variable _superscript_mapping Undocumented
Class Variable _use_unicode Undocumented
Instance Variable _symbol Undocumented
@classmethod
def basis(cls, deg, domain=None, window=None, symbol='x'): (source)

Series basis polynomial of degree deg.

Returns the series representing the basis polynomial of degree deg.

New in version 1.7.0.
Parameters
deg:intDegree of the basis polynomial for the series. Must be >= 0.
domain:{None, array_like}, optionalIf 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}, optionalIf 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.
symbol:str, optionalSymbol representing the independent variable. Default is 'x'.
Returns
seriesnew_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): (source)

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.

See Also

convert
similar instance method
Parameters
series:seriesThe series instance to be converted.
domain:{None, array_like}, optionalIf 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}, optionalIf 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
seriesnew_series - A series of the same kind as the calling class and equal to series when evaluated.
@classmethod
def fit(cls, x, y, deg, domain=None, rcond=None, full=False, w=None, window=None, symbol='x'): (source)

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_likeDegree(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], []}, optionalDomain 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, optionalRelative 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, optionalSwitch 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.
symbol:str, optionalSymbol representing the independent variable. Default is 'x'.
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, symbol='x'): (source)

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_likeList of roots.
domain:{[], None, array_like}, optionalDomain 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}, optionalWindow for the returned series. If None the class window is used. The default is None.
symbol:str, optionalSymbol representing the independent variable. Default is 'x'.
Returns
seriesnew_series - Series with the specified roots.
@classmethod
def identity(cls, domain=None, window=None, symbol='x'): (source)

Identity function.

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

Parameters
domain:{None, array_like}, optionalIf 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}, optionalIf 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.
symbol:str, optionalSymbol representing the independent variable. Default is 'x'.
Returns
seriesnew_series - Series of representing the identity.
def __add__(self, other): (source)

Undocumented

def __call__(self, arg): (source)

Undocumented

def __divmod__(self, other): (source)

Undocumented

def __eq__(self, other): (source)

Undocumented

def __floordiv__(self, other): (source)

Undocumented

def __format__(self, fmt_str): (source)

Undocumented

def __getstate__(self): (source)

Undocumented

def __init__(self, coef, domain=None, window=None, symbol='x'): (source)

Undocumented

def __iter__(self): (source)

Undocumented

def __len__(self): (source)

Undocumented

def __mod__(self, other): (source)

Undocumented

def __mul__(self, other): (source)

Undocumented

def __ne__(self, other): (source)

Undocumented

def __neg__(self): (source)

Undocumented

def __pos__(self): (source)

Undocumented

def __pow__(self, other): (source)

Undocumented

def __radd__(self, other): (source)

Undocumented

def __rdiv__(self, other): (source)

Undocumented

def __rdivmod__(self, other): (source)

Undocumented

def __repr__(self): (source)

Undocumented

def __rfloordiv__(self, other): (source)

Undocumented

def __rmod__(self, other): (source)

Undocumented

def __rmul__(self, other): (source)

Undocumented

def __rsub__(self, other): (source)

Undocumented

def __rtruediv__(self, other): (source)

Undocumented

def __setstate__(self, dict): (source)

Undocumented

def __str__(self): (source)

Undocumented

def __sub__(self, other): (source)

Undocumented

def __truediv__(self, other): (source)

Undocumented

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

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

Notes

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

Parameters
domain:array_like, optionalThe domain of the converted series. If the value is None, the default domain of kind is used.
kind:class, optionalThe 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, optionalThe window of the converted series. If the value is None, the default window of kind is used.
Returns
seriesnew_series - The returned class can be of different type than the current instance and/or have a different domain and/or different window.
def copy(self): (source)

Return a copy.

Returns
seriesnew_series - Copy of self.
def cutdeg(self, deg): (source)

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 intThe series is reduced to degree deg by discarding the high order terms. The value of deg must be a non-negative integer.
Returns
seriesnew_series - New instance of series with reduced degree.
def degree(self): (source)

The degree of the series.

New in version 1.5.0.
Returns
intdegree - Degree of the series, one less than the number of coefficients.
def deriv(self, m=1): (source)

Differentiate.

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

Parameters
m:non-negative intFind the derivative of order m.
Returns
seriesnew_series - A new series representing the derivative. The domain is the same as the domain of the differentiated series.
def has_samecoef(self, other): (source)

Check if coefficients match.

New in version 1.6.0.
Parameters
other:class instanceThe other class must have the coef attribute.
Returns
booleanbool - True if the coefficients are the same, False otherwise.
def has_samedomain(self, other): (source)

Check if domains match.

New in version 1.6.0.
Parameters
other:class instanceThe other class must have the domain attribute.
Returns
booleanbool - True if the domains are the same, False otherwise.
def has_sametype(self, other): (source)

Check if types match.

New in version 1.7.0.
Parameters
other:objectClass instance.
Returns
booleanbool - True if other is same class as self
def has_samewindow(self, other): (source)

Check if windows match.

New in version 1.6.0.
Parameters
other:class instanceThe other class must have the window attribute.
Returns
booleanbool - True if the windows are the same, False otherwise.
def integ(self, m=1, k=[], lbnd=None): (source)

Integrate.

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

Parameters
m:non-negative intThe number of integrations to perform.
k:array_likeIntegration 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:ScalarThe lower bound of the definite integral.
Returns
seriesnew_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): (source)

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, optionalNumber of point pairs to return. The default value is 100.
domain:{None, array_like}, optionalIf 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
ndarrayx, y - 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): (source)

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.

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
Returns
float or complexoff, scl - The mapping function is defined by off + scl*x.
def roots(self): (source)

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
ndarrayroots - Array containing the roots of the series.
def trim(self, tol=0): (source)

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
seriesnew_series - New instance of series with trimmed coefficients.
def truncate(self, size): (source)

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 intThe series is reduced to length size by discarding the high degree terms. The value of size must be a positive integer.
Returns
seriesnew_series - New instance of series with truncated coefficients.
__array_ufunc__ = (source)

Undocumented

__hash__ = (source)

Undocumented

maxpower: int = (source)

Undocumented

__dict__ = (source)

Undocumented

Undocumented

@classmethod
def _repr_latex_term(cls, i, arg_str, needs_parens): (source)

Undocumented

@classmethod
def _str_term_ascii(cls, i, arg_str): (source)

String representation of a single polynomial term using ** and _ to represent superscripts and subscripts, respectively.

@classmethod
def _str_term_unicode(cls, i, arg_str): (source)

String representation of single polynomial term using unicode characters for superscripts and subscripts.

Undocumented

Undocumented

Undocumented

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

Undocumented

Undocumented

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

Undocumented

Undocumented

Undocumented

Undocumented

@staticmethod
def _repr_latex_scalar(x, parens=False): (source)

Undocumented

Undocumented

def _generate_string(self, term_method): (source)

Generate the full string representation of the polynomial, using term_method to generate each polynomial term.

def _get_coefficients(self, other): (source)

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:anythingObject to be checked.
Returns
coefThe coefficients of`other` if it is a compatible instance, of ABCPolyBase, otherwise other.
Raises
TypeErrorWhen other is an incompatible instance of ABCPolyBase.
def _repr_latex_(self): (source)

Undocumented

_subscript_mapping = (source)

Undocumented

_superscript_mapping = (source)

Undocumented

_use_unicode = (source)

Undocumented

Undocumented