🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEscipy

scipy Documentation

LOADING ENGINE...

interpolate.Rbf()

AI & DATA SCIENCE // interpolate-rbf

scipy.interpolate.Rbf() performs radial basis function interpolation, fitting a smooth surface through scattered data points, especially useful for multi-dimensional or irregularly-spaced data.

Syntax

scipy.interpolate.Rbf(*args, function='multiquadric')

Deep Dive Course

Unlike interp1d(), which only works along a single dimension with sorted data, Rbf(), radial basis function interpolation, handles scattered, irregularly-placed points in two or more dimensions by building the interpolated surface as a weighted sum of radial basis functions centered at each known data point — the function parameter selects the specific basis function shape used, 'multiquadric' by default, with alternatives like 'gaussian' and 'linear' also available. This makes it well suited for interpolating things like elevation data from unevenly-spaced survey points, where a simple grid-based method wouldn't directly apply.

1Understanding interpolate.Rbf()

Unlike interp1d(), which only works along a single dimension with sorted data, Rbf(), radial basis function interpolation, handles scattered, irregularly-placed points in two or more dimensions by building the interpolated surface as a weighted sum of radial basis functions centered at each known data point — the function parameter selects the specific basis function shape used, 'multiquadric' by default, with alternatives like 'gaussian' and 'linear' also available. This makes it well suited for interpolating things like elevation data from unevenly-spaced survey points, where a simple grid-based method wouldn't directly apply.

💡

Use Rbf() specifically for scattered, irregularly-spaced multi-dimensional data, like unevenly-sampled 2D or 3D measurements — interp1d() and UnivariateSpline() are limited to a single dimension with ordered data, which doesn't fit scattered multi-dimensional points at all.

editor.html
from scipy.interpolate import Rbf
import numpy as np

x = np.array([0, 1, 2, 3])
y = np.array([0, 0, 1, 1])
z = np.array([10, 12, 14, 18])
rbf = Rbf(x, y, z)
print(round(float(rbf(1.5, 0.5)), 2))
localhost:3000

2Practical Example

Here is a real-world application of interpolate.Rbf() showing how it is used in production SciPy code.

editor.html
from scipy.interpolate import Rbf
import numpy as np

x = np.array([0, 1, 2, 3, 4])
y = np.array([0, 1, 4, 9, 16])
rbf = Rbf(x, y, function="linear")
print(round(float(rbf(2.5)), 2))
localhost:3000

3Best Practices

Follow these guidelines when working with interpolate.Rbf():

1. Use Rbf() for genuinely scattered, multi-dimensional data, rather than trying to force it into a single-dimensional interp1d()/UnivariateSpline() call

2. Experiment with different function options, multiquadric, gaussian, linear, etc., and compare results, since the best basis function choice depends on the specific data's shape

3. Be aware Rbf() can become slow and memory-intensive for a very large number of data points, since it involves solving a system scaling with the number of points

⚠️

Tip: Use Rbf() specifically for scattered, irregularly-spaced multi-dimensional data, like unevenly-sampled 2D or 3D measurements — interp1d() and UnivariateSpline() are limited to a single dimension with ordered data, which doesn't fit scattered multi-dimensional points at all.

editor.html
from scipy.interpolate import Rbf
import numpy as np

x = np.array([0, 1, 2, 3])
y = np.array([0, 0, 1, 1])
z = np.array([10, 12, 14, 18])
rbf = Rbf(x, y, z)
print(round(float(rbf(1.5, 0.5)), 2))
localhost:3000

Examples

Example 01Basic Usage
from scipy.interpolate import Rbf
import numpy as np

x = np.array([0, 1, 2, 3])
y = np.array([0, 0, 1, 1])
z = np.array([10, 12, 14, 18])
rbf = Rbf(x, y, z)
print(round(float(rbf(1.5, 0.5)), 2))
Example 02Advanced Example
from scipy.interpolate import Rbf
import numpy as np

x = np.array([0, 1, 2, 3, 4])
y = np.array([0, 1, 4, 9, 16])
rbf = Rbf(x, y, function="linear")
print(round(float(rbf(2.5)), 2))

Best Practices

  • Use Rbf() for genuinely scattered, multi-dimensional data, rather than trying to force it into a single-dimensional interp1d()/UnivariateSpline() call
  • Experiment with different function options, multiquadric, gaussian, linear, etc., and compare results, since the best basis function choice depends on the specific data's shape
  • Be aware Rbf() can become slow and memory-intensive for a very large number of data points, since it involves solving a system scaling with the number of points

Interview Question

Why can't you use scipy.interpolate.interp1d() for a set of scattered (x, y) points that don't lie along a simple, sorted line, like elevation measurements taken at random locations on a map?

Hint: Think about what interp1d() specifically requires of its input data's structure.

interp1d() is designed specifically for one-dimensional interpolation, where the y value depends on a single ordered input variable x, and it requires the x values to be sorted so it can find which two neighboring points to interpolate between. Scattered 2D or 3D data, like elevation values recorded at irregular map coordinates, has no single ordered dimension to sort by and no natural notion of two neighboring points to interpolate linearly between, which is exactly the situation Rbf() is designed for instead, building an interpolated surface based on distances to every known point rather than requiring a sorted, single-dimensional structure.

Exercises

MediumPractice using interpolate.Rbf() in a real scenario.
View Solution
from scipy.interpolate import Rbf
import numpy as np

x = np.array([0, 1, 2, 3])
y = np.array([0, 0, 1, 1])
z = np.array([10, 12, 14, 18])
rbf = Rbf(x, y, z)
print(round(float(rbf(1.5, 0.5)), 2))

Frequently Asked Questions

Why can't you use scipy.interpolate.interp1d() for a set of scattered (x, y) points that don't lie along a simple, sorted line, like elevation measurements taken at random locations on a map?

interp1d() is designed specifically for one-dimensional interpolation, where the y value depends on a single ordered input variable x, and it requires the x values to be sorted so it can find which two neighboring points to interpolate between. Scattered 2D or 3D data, like elevation values recorded at irregular map coordinates, has no single ordered dimension to sort by and no natural notion of two neighboring points to interpolate linearly between, which is exactly the situation Rbf() is designed for instead, building an interpolated surface based on distances to every known point rather than requiring a sorted, single-dimensional structure.

Related Functions

interpolate-interp1dinterpolate-univariatesplinespatial-kdtree