songololo
songololo

Reputation: 4964

Scipy Interpolate RectBivariateSpline constructor returns an error

I am trying to instantiate a Scipy Interpolate RectBivariateSpline as follows:

import numpy as np
from scipy.interpolate import RectBivariateSpline

x = np.array([1,2,3,4])
y = np.array([1,2,3])
vals = np.array([
    [4,1,4],
    [4,2,3],
    [3,7,4],
    [2,4,5]
])

print(x.shape)  # (4,)
print(y.shape)  # (3,)
print(vals.shape)  # (4, 3)

rect_B_spline = RectBivariateSpline(x, y, vals)

However, it returns this error:

Traceback (most recent call last):
  File "path/file", line 15, in <module>
    rect_B_spline = RectBivariateSpline(x, y, vals)
  File "path/file", line 1061, in __init__
    ye, kx, ky, s)
dfitpack.error: (my>ky) failed for hidden my: regrid_smth:my=3

Would appreciate any clues as to what the dfitpack error describes and how to resolve.

Upvotes: 3

Views: 4168

Answers (1)

Jon Custer
Jon Custer

Reputation: 704

By default, RectBivariateSpline uses a degree 3 spline. By providing only 3 points along the y-axis it cannot do that. Adding ky=2 to the argument list fixes the problem, as does having more data.

Upvotes: 7

Related Questions