MCPcopy Create free account
hub / github.com/numpy/numpy / polyval

Function polyval

numpy/polynomial/polynomial.py:664–757  ·  view source on GitHub ↗

Evaluate a polynomial at points x. If `c` is of length `n + 1`, this function returns the value .. math:: p(x) = c_0 + c_1 * x + ... + c_n * x^n The parameter `x` is converted to an array only if it is a tuple or a list, otherwise it is treated as a scalar. In either case, ei

(x, c, tensor=True)

Source from the content-addressed store, hash-verified

662
663
664def polyval(x, c, tensor=True):
665 """
666 Evaluate a polynomial at points x.
667
668 If `c` is of length `n + 1`, this function returns the value
669
670 .. math:: p(x) = c_0 + c_1 * x + ... + c_n * x^n
671
672 The parameter `x` is converted to an array only if it is a tuple or a
673 list, otherwise it is treated as a scalar. In either case, either `x`
674 or its elements must support multiplication and addition both with
675 themselves and with the elements of `c`.
676
677 If `c` is a 1-D array, then `p(x)` will have the same shape as `x`. If
678 `c` is multidimensional, then the shape of the result depends on the
679 value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
680 x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
681 scalars have shape (,).
682
683 Trailing zeros in the coefficients will be used in the evaluation, so
684 they should be avoided if efficiency is a concern.
685
686 Parameters
687 ----------
688 x : array_like, compatible object
689 If `x` is a list or tuple, it is converted to an ndarray, otherwise
690 it is left unchanged and treated as a scalar. In either case, `x`
691 or its elements must support addition and multiplication with
692 with themselves and with the elements of `c`.
693 c : array_like
694 Array of coefficients ordered so that the coefficients for terms of
695 degree n are contained in c[n]. If `c` is multidimensional the
696 remaining indices enumerate multiple polynomials. In the two
697 dimensional case the coefficients may be thought of as stored in
698 the columns of `c`.
699 tensor : boolean, optional
700 If True, the shape of the coefficient array is extended with ones
701 on the right, one for each dimension of `x`. Scalars have dimension 0
702 for this action. The result is that every column of coefficients in
703 `c` is evaluated for every element of `x`. If False, `x` is broadcast
704 over the columns of `c` for the evaluation. This keyword is useful
705 when `c` is multidimensional. The default value is True.
706
707 .. versionadded:: 1.7.0
708
709 Returns
710 -------
711 values : ndarray, compatible object
712 The shape of the returned array is described above.
713
714 See Also
715 --------
716 polyval2d, polygrid2d, polyval3d, polygrid3d
717
718 Notes
719 -----
720 The evaluation uses Horner's method.
721

Callers 11

TestEvaluationClass · 0.90
test_legvalMethod · 0.90
TestEvaluationClass · 0.90
test_hermvalMethod · 0.90
TestEvaluationClass · 0.90
test_hermevalMethod · 0.90
TestEvaluationClass · 0.90
test_lagvalMethod · 0.90
TestEvaluationClass · 0.90
test_chebvalMethod · 0.90
polyintFunction · 0.70

Calls 1

reshapeMethod · 0.80

Tested by 5

test_legvalMethod · 0.72
test_hermvalMethod · 0.72
test_hermevalMethod · 0.72
test_lagvalMethod · 0.72
test_chebvalMethod · 0.72