espnet2.enh.layers.dnsmos.poly1d
Less than 1 minute
espnet2.enh.layers.dnsmos.poly1d
espnet2.enh.layers.dnsmos.poly1d(coefficients, use_numpy=False)
Construct a polynomial function from given coefficients.
This function creates a polynomial function of the form: f(x) = a_n * x^n + a_(n-1) * x^(n-1) + … + a_1 * x + a_0 where the coefficients are provided in the list coefficients in the order of highest degree to lowest.
If use_numpy is set to True, the function returns a numpy polynomial object instead of a custom function.
- Parameters:
- coefficients (list or tuple) – Coefficients of the polynomial, where the first element is the coefficient of the highest degree.
- use_numpy (bool) – If True, return a numpy polynomial object. Defaults to False.
- Returns: A polynomial function that can be called with a single argument or a numpy polynomial object.
- Return type: function or np.poly1d
Examples
>>> p = poly1d([1, -3, 2]) # Creates the polynomial x^2 - 3x + 2
>>> p(1) # Output: 0
>>> p(2) # Output: 0
>>> p(3) # Output: 2
>>> np_poly = poly1d([1, -3, 2], use_numpy=True)
>>> np_poly(1) # Output: 0
>>> np_poly(2) # Output: 0
>>> np_poly(3) # Output: 2