Help on module nicedisplay_numpy_polynomial_Polynomial: NAME nicedisplay_numpy_polynomial_Polynomial - A tiny modification of the method numpy.polynomial.Polynomial.__str__ to nicely display a polynomials. FILE /home/lilian/publis/snippets/small-overload-of-the/nicedisplay_numpy_polynomial_Polynomial.py DESCRIPTION Cf. https://docs.scipy.org/doc/numpy/reference/generated/numpy.polynomial.polynomial.Polynomial.html for more details about the original class. - *Online:* https://bitbucket.org/snippets/lbesson/j6dpz#file-nicedisplay_numpy_polynomial_Polynomial.py - *Author:* Lilian Besson, for http://perso.crans.org/besson/infoMP/oraux/solutions/PSI_Mat2_2015_25.html, - *License:* MIT Licence (http://lbesson.mit-license.org). CLASSES numpy.polynomial.polynomial.Polynomial(numpy.polynomial._polybase.ABCPolyBase) MyPolynomial class MyPolynomial(numpy.polynomial.polynomial.Polynomial) | Small extension of the numpy.polynomial.Polynomial class to change its __str__ method. | | Method resolution order: | MyPolynomial | numpy.polynomial.polynomial.Polynomial | numpy.polynomial._polybase.ABCPolyBase | __builtin__.object | | Methods defined here: | | __str__(self) | Improved __str__ method to print nicely the polynomial as we write it in maths. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset([]) | | ---------------------------------------------------------------------- | Data and other attributes inherited from numpy.polynomial.polynomial.Polynomial: | | domain = array([-1, 1]) | | nickname = 'poly' | | window = array([-1, 1]) | | ---------------------------------------------------------------------- | Methods inherited from numpy.polynomial._polybase.ABCPolyBase: | | __add__(self, other) | | __call__(self, arg) | | __div__(self, other) | | __divmod__(self, other) | | __eq__(self, other) | | __floordiv__(self, other) | | __getstate__(self) | | __init__(self, coef, domain=None, window=None) | | __iter__(self) | | __len__(self) | | __mod__(self, other) | | __mul__(self, other) | | __ne__(self, other) | | __neg__(self) | | __pos__(self) | | __pow__(self, other) | | __radd__(self, other) | | __rdiv__(self, other) | | __rdivmod__(self, other) | | __repr__(self) | | __rfloordiv__(self, other) | | __rmod__(self, other) | | __rmul__(self, other) | | __rsub__(self, other) | | __rtruediv__(self, other) | | __setstate__(self, dict) | | __sub__(self, other) | | __truediv__(self, other) | | 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. | | Examples | -------- | | copy(self) | Return a copy. | | Returns | ------- | new_series : series | Copy of self. | | 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. | | .. versionadded:: 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. | | degree(self) | The degree of the series. | | .. versionadded:: 1.5.0 | | Returns | ------- | degree : int | Degree of the series, one less than the number of coefficients. | | 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. | | has_samecoef(self, other) | Check if coefficients match. | | .. versionadded:: 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. | | has_samedomain(self, other) | Check if domains match. | | .. versionadded:: 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. | | has_sametype(self, other) | Check if types match. | | .. versionadded:: 1.7.0 | | Parameters | ---------- | other : object | Class instance. | | Returns | ------- | bool : boolean | True if other is same class as self | | has_samewindow(self, other) | Check if windows match. | | .. versionadded:: 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. | | 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. | | 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. | | .. versionadded:: 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. | | 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 | | 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. | | 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 | Contains the new set of coefficients. | | 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. | | ---------------------------------------------------------------------- | Class methods inherited from numpy.polynomial._polybase.ABCPolyBase: | | basis(cls, deg, domain=None, window=None) from abc.ABCMeta | Series basis polynomial of degree `deg`. | | Returns the series representing the basis polynomial of degree `deg`. | | .. versionadded:: 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. | | cast(cls, series, domain=None, window=None) from abc.ABCMeta | 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. | | .. versionadded:: 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 | | fit(cls, x, y, deg, domain=None, rcond=None, full=False, w=None, window=None) from abc.ABCMeta | 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,) or (M, K) | y-coordinates of the sample points. Several data sets of sample | points sharing the same x-coordinates can be fitted at once by | passing in a 2D-array that contains one dataset per column. | deg : int | Degree of the fitting polynomial. | 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 contribution of each point | ``(x[i],y[i])`` to the fit is weighted by `w[i]`. Ideally the | weights are chosen so that the errors of the products | ``w[i]*y[i]`` all have the same variance. The default value is | None. | | .. versionadded:: 1.5.0 | window : {[beg, end]}, optional | Window to use for the returned series. The default | value is the default class domain | | .. versionadded:: 1.6.0 | | Returns | ------- | new_series : series | A series that represents the least squares fit to the data and | has the domain specified in the call. | | [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`. | | fromroots(cls, roots, domain=[], window=None) from abc.ABCMeta | 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. | | identity(cls, domain=None, window=None) from abc.ABCMeta | 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. | | ---------------------------------------------------------------------- | Data descriptors inherited from numpy.polynomial._polybase.ABCPolyBase: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Data and other attributes inherited from numpy.polynomial._polybase.ABCPolyBase: | | __array_priority__ = 1000 | | __hash__ = None | | __metaclass__ = | Metaclass for defining Abstract Base Classes (ABCs). | | Use this metaclass to create an ABC. An ABC can be subclassed | directly, and then acts as a mix-in class. You can also register | unrelated concrete classes (even built-in classes) and unrelated | ABCs as 'virtual subclasses' -- these and their descendants will | be considered subclasses of the registering ABC by the built-in | issubclass() function, but the registering ABC won't show up in | their MRO (Method Resolution Order) nor will method | implementations defined by the registering ABC be callable (not | even via super()). | | maxpower = 100 P = class MyPolynomial(numpy.polynomial.polynomial.Polynomial) | Small extension of the numpy.polynomial.Polynomial class to change its __str__ method. | | Method resolution order: | MyPolynomial | numpy.polynomial.polynomial.Polynomial | numpy.polynomial._polybase.ABCPolyBase | __builtin__.object | | Methods defined here: | | __str__(self) | Improved __str__ method to print nicely the polynomial as we write it in maths. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset([]) | | ---------------------------------------------------------------------- | Data and other attributes inherited from numpy.polynomial.polynomial.Polynomial: | | domain = array([-1, 1]) | | nickname = 'poly' | | window = array([-1, 1]) | | ---------------------------------------------------------------------- | Methods inherited from numpy.polynomial._polybase.ABCPolyBase: | | __add__(self, other) | | __call__(self, arg) | | __div__(self, other) | | __divmod__(self, other) | | __eq__(self, other) | | __floordiv__(self, other) | | __getstate__(self) | | __init__(self, coef, domain=None, window=None) | | __iter__(self) | | __len__(self) | | __mod__(self, other) | | __mul__(self, other) | | __ne__(self, other) | | __neg__(self) | | __pos__(self) | | __pow__(self, other) | | __radd__(self, other) | | __rdiv__(self, other) | | __rdivmod__(self, other) | | __repr__(self) | | __rfloordiv__(self, other) | | __rmod__(self, other) | | __rmul__(self, other) | | __rsub__(self, other) | | __rtruediv__(self, other) | | __setstate__(self, dict) | | __sub__(self, other) | | __truediv__(self, other) | | 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. | | Examples | -------- | | copy(self) | Return a copy. | | Returns | ------- | new_series : series | Copy of self. | | 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. | | .. versionadded:: 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. | | degree(self) | The degree of the series. | | .. versionadded:: 1.5.0 | | Returns | ------- | degree : int | Degree of the series, one less than the number of coefficients. | | 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. | | has_samecoef(self, other) | Check if coefficients match. | | .. versionadded:: 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. | | has_samedomain(self, other) | Check if domains match. | | .. versionadded:: 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. | | has_sametype(self, other) | Check if types match. | | .. versionadded:: 1.7.0 | | Parameters | ---------- | other : object | Class instance. | | Returns | ------- | bool : boolean | True if other is same class as self | | has_samewindow(self, other) | Check if windows match. | | .. versionadded:: 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. | | 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. | | 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. | | .. versionadded:: 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. | | 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 | | 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. | | 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 | Contains the new set of coefficients. | | 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. | | ---------------------------------------------------------------------- | Class methods inherited from numpy.polynomial._polybase.ABCPolyBase: | | basis(cls, deg, domain=None, window=None) from abc.ABCMeta | Series basis polynomial of degree `deg`. | | Returns the series representing the basis polynomial of degree `deg`. | | .. versionadded:: 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. | | cast(cls, series, domain=None, window=None) from abc.ABCMeta | 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. | | .. versionadded:: 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 | | fit(cls, x, y, deg, domain=None, rcond=None, full=False, w=None, window=None) from abc.ABCMeta | 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,) or (M, K) | y-coordinates of the sample points. Several data sets of sample | points sharing the same x-coordinates can be fitted at once by | passing in a 2D-array that contains one dataset per column. | deg : int | Degree of the fitting polynomial. | 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 contribution of each point | ``(x[i],y[i])`` to the fit is weighted by `w[i]`. Ideally the | weights are chosen so that the errors of the products | ``w[i]*y[i]`` all have the same variance. The default value is | None. | | .. versionadded:: 1.5.0 | window : {[beg, end]}, optional | Window to use for the returned series. The default | value is the default class domain | | .. versionadded:: 1.6.0 | | Returns | ------- | new_series : series | A series that represents the least squares fit to the data and | has the domain specified in the call. | | [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`. | | fromroots(cls, roots, domain=[], window=None) from abc.ABCMeta | 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. | | identity(cls, domain=None, window=None) from abc.ABCMeta | 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. | | ---------------------------------------------------------------------- | Data descriptors inherited from numpy.polynomial._polybase.ABCPolyBase: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Data and other attributes inherited from numpy.polynomial._polybase.ABCPolyBase: | | __array_priority__ = 1000 | | __hash__ = None | | __metaclass__ = | Metaclass for defining Abstract Base Classes (ABCs). | | Use this metaclass to create an ABC. An ABC can be subclassed | directly, and then acts as a mix-in class. You can also register | unrelated concrete classes (even built-in classes) and unrelated | ABCs as 'virtual subclasses' -- these and their descendants will | be considered subclasses of the registering ABC by the built-in | issubclass() function, but the registering ABC won't show up in | their MRO (Method Resolution Order) nor will method | implementations defined by the registering ABC be callable (not | even via super()). | | maxpower = 100 FUNCTIONS test() Some tests of our improved ``__str__`` method. First, let start by defining the monome X: >>> P = MyPolynomial >>> X = P([0, 1]) # We define the monome X, to work with it efficiently >>> print(X) X And then a few other polynomials: >>> Q1 = 1 + 2*X + 17*X**3 >>> print(Q1) 1 + 2 * X + 17 * X**3 >>> Q2 = Q1 - 2*X >>> print(Q2) 1 + 17 * X**3 We can check that the negative signs work too: >>> Q3 = -1 - 2*X - 17*X**3 >>> print(Q3) (-1) + (-2) * X + (-17) * X**3 >>> print(-Q3) 1 + 2 * X + 17 * X**3 And with crazily long polynomials: >>> Q4 = (1 + 2*X + 17*X**3) ** 20 >>> print(Q4) # doctest: +ELLIPSIS 1 + 40 * X + 760 * X**2 + 9460 * X**3 + 90440 * X**4 + ... + 4064231406647572451819520 * X**60 >>> Q5 = (1 + 2*X + 17*X**3) ** 100 >>> print(Q5) # doctest: +ELLIPSIS 1 + 200 * X + 19800 * X**2 + 1295300 * X**3 + ... + 1108899372780782949283060780215564719143115314569706274981249422854766735454757111223455545827324114733078454801811428605952 * X**300 It works nicely ! DATA X = MyPolynomial([ 0., 1.], [-1, 1], [-1, 1]) division = _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192... print_function = _Feature((2, 6, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0)...