Skip to main content
`Ctrl`+`K`
scipy.interpolate.

# BPoly

class scipy.interpolate.BPoly(c, x, extrapolate=None, axis=0)

  Piecewise polynomial in the Bernstein basis.

  The polynomial between `x[i]` and `x[i + 1]` is written in the Bernstein polynomial basis:

      S = sum(c[a, i] * b(a, k; x) for a in range(k+1)),

  where `k` is the degree of the polynomial, and:

      b(a, k; x) = binom(k, a) * t**a * (1 - t)**(k - a),

  with `t = (x - x[i]) / (x[i+1] - x[i])` and `binom` is the binomial coefficient.

  Parameters:
    c ndarray, shape (k, m, …)

      Polynomial coefficients, order k and m intervals

    x ndarray, shape (m+1,)

      Polynomial breakpoints. Must be sorted in either increasing or decreasing order.

    extrapolate{bool, ‘periodic’, None}, optional

      If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If ‘periodic’, periodic extrapolation is used. If None (default), it is set to True. See Out-of-bounds behavior.

    axis int, optional

      Interpolation axis. Default is zero.

  Attributes:
    x ndarray

      Breakpoints.

    c ndarray

      Coefficients of the polynomials. They are reshaped to a 3-D array with the last dimension representing the trailing dimensions of the original coefficient array.

    axis int

      Interpolation axis.

  Methods

  `__call__`(x[, nu, extrapolate]) | Evaluate the piecewise polynomial or its derivative.
  `extend`(c, x) | Add additional breakpoints and coefficients to the polynomial.
  `derivative`([nu]) | Construct a new piecewise polynomial representing the derivative.
  `antiderivative`([nu]) | Construct a new piecewise polynomial representing the antiderivative.
  `integrate`(a, b[, extrapolate]) | Compute a definite integral over a piecewise polynomial.
  `construct_fast`(c, x[, extrapolate, axis]) | Construct the piecewise polynomial without making checks.
  `from_power_basis`(pp[, extrapolate]) | Construct a piecewise polynomial in Bernstein basis from a power basis polynomial.
  `from_derivatives`(xi, yi[, orders, extrapolate]) | Construct a piecewise polynomial in the Bernstein basis, compatible with the specified values and derivatives at breakpoints.

  See also

  `PPoly`

    piecewise polynomials in the power basis

  Notes

  Properties of Bernstein polynomials are well documented in the literature, see for example [1] [2] [3].

  Array API Standard Support

  `BPoly` has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable `SCIPY_ARRAY_API=1` and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

  Library | CPU | GPU
  --- | --- | ---
  NumPy | ✅ | n/a
  CuPy | n/a | ✅
  PyTorch | ✅ | ⛔
  JAX | ⚠️ no JIT | ⛔
  Dask | ⛔ | n/a

  If a bpoly object is called on an input array `x` with namespace different from the namespace `xp` of the breakpoints and coefficients with which the bpoly object was instantiated, an attempt will be made to coerce `x` to the `xp` namespace. If the conversion succeeds, the output will be an array from the `xp` namespace. Mixing namespaces in this way is not recommended.

  See Support for the array API standard for more information.

  References

  [1]

  https://en.wikipedia.org/wiki/Bernstein_polynomial

  [2]

  Kenneth I. Joy, Bernstein polynomials, http://www.idav.ucdavis.edu/education/CAGDNotes/Bernstein-Polynomials.pdf

  [3]

  E. H. Doha, A. H. Bhrawy, and M. A. Saker, Boundary Value Problems, vol 2011, article ID 829546, DOI:10.1155/2011/829543.

  Examples

      >>> from scipy.interpolate import BPoly
      >>> x = [0, 1]
      >>> c = [[1], [2], [3]]
      >>> bp = BPoly(c, x)

  This creates a 2nd order polynomial

  \[\begin{split}B(x) = 1 \times b_{0, 2}(x) + 2 \times b_{1, 2}(x) + 3 \times b_{2, 2}(x) \\ = 1 \times (1-x)^2 + 2 \times 2 x (1 - x) + 3 \times x^2\end{split}\]