
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - interpolate.BarycentricInterpolator() Function
scipy.interpolate.BarycentricInterpolator() is a Python function that performs polynomial interpolation using the Barycentric Lagrange interpolation formula. This method is particularly efficient and numerically stable for higher-degree polynomials compared to other forms of polynomial interpolation.
It constructs a polynomial that passes through a given set of points (xi, yi) by allowing for fast evaluation of the interpolating polynomial at new points. The BarycentricInterpolator() function avoids the direct computation of Lagrange polynomials by making it more stable when dealing with large data sets or high-degree polynomials. It is useful for smoothly estimating intermediate values between data points.
Syntax
Following is the syntax of the function scipy.interpolate.BarycentricInterpolator() to perform polynomial interpolation −
scipy.interpolate.BarycentricInterpolator(xi, yi=None, axis=0, *, wi=None, random_state=None)
Parameters
Here are the parameters of the scipy.interpolate.BarycentricInterpolator() function −
- xi(array-like): The x-coordinates of the data points. These points must be distinct.
- yi(array-like, optional): The corresponding y-coordinates of the function at each point in xi. If not provided then yi can be supplied later when the interpolator is called.
- axis(int, optional): The axis along which to interpolate when dealing with multi-dimensional yi arrays. The default value is 0.
- wi(array-like, optional): Barycentric weights for the data points. If not provided then the weights are calculated internally based on xi.
- random_state({None, int, numpy.random.Generator}, optional): Controls the reproducibility when generating random weights, if applicable. If random_state is an integer then it sets the seed, if its a Generator then its used for creating random numbers, if None then the global random generator is used.
Return Value
The scipy.interpolate.BarycentricInterpolator() function returns a callable object that can be used to perform interpolation at new data points.
Basic Example
Following is the example which shows how to create a Barycentric interpolator for a set of points and use it to estimate values at new points with the help of the scipy.interpolate.BarycentricInterpolator() function −
import numpy as np from scipy.interpolate import BarycentricInterpolator import matplotlib.pyplot as plt # Define known data points x = np.array([0, 1, 2, 3, 4, 5]) y = np.array([0, 1, 4, 9, 16, 25]) # Create the interpolator interp = BarycentricInterpolator(x, y) # Define new points where interpolation is needed x_new = np.linspace(0, 5, 100) y_new = interp(x_new) # Plot the results plt.plot(x, y, 'o', label='Known points') plt.plot(x_new, y_new, '-', label='Interpolated curve') plt.legend() plt.xlabel('x') plt.ylabel('y') plt.title('Barycentric Interpolation') plt.show()
Here is the output of the scipy.interpolate.BarycentricInterpolator() function −

Lazy Initialization(Setting yi Later)
Lazy Initialization in the view of interpolation typically means that we can define the interpolation object first and then set the y values (yi) later which can be useful when we need to postpone specifying certain data until later in your workflow. Here is the example of it −
import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import BarycentricInterpolator # Step 1: Initialize known x-values (independent variable) x = np.linspace(0, 10, num=5) # x-coordinates # Step 2: Lazy Initialization: Create a BarycentricInterpolator object without specifying yi (y-values) interpolator = BarycentricInterpolator(x, np.zeros_like(x)) # Temporary yi of zeros # Some other computations or data fetching # Simulate a delay or other operations here # Let's say we want to calculate yi using a function later # Step 3: Now set the y-values later (Lazy Initialization of yi) y = np.sin(x) # Let's define yi as the sine of the x-values interpolator = BarycentricInterpolator(x, y) # Now initialize the function with yi # Step 4: Define new x-values for interpolation x_new = np.linspace(0, 10, num=100) # Step 5: Interpolate for the new x-values y_new = interpolator(x_new) # Step 6: Plotting the results plt.plot(x, y, 'o', label='data points (original)') plt.plot(x_new, y_new, '-', label='Barycentric interpolation') plt.title('Lazy Initialization with BarycentricInterpolator') plt.xlabel('x-axis') plt.ylabel('y-axis') plt.legend() plt.grid() plt.show()
Here is the output of the scipy.interpolate.BarycentricInterpolator() function which is used for lazy initialization −

Multi-dimensional Interpolation
Here in this example if yi is multi-dimensional then we will specify the axis parameter to control how interpolation is applied −
import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import BarycentricInterpolator # Known data points x = np.array([0, 1, 2, 3]) y = np.array([[1, 2], [2, 3], [3, 5], [4, 7]]) # Create the interpolator, specifying axis=0 (interpolating along the rows) interp = BarycentricInterpolator(x, y, axis=0) # New points for interpolation x_new = np.linspace(0, 3, 50) y_new = interp(x_new) plt.plot(x_new, y_new[:, 0], label='Interpolated dim 1') plt.plot(x_new, y_new[:, 1], label='Interpolated dim 2') plt.legend() plt.title('Multi-dimensional Barycentric Interpolation') plt.show()
Following is the output of the scipy.interpolate.BarycentricInterpolator() function applied for multi-dimensional interpolation −
