Scipy.interp2d warning and big grid errors

I am trying to interpolate a two-dimensional function, and I am faced with what I consider to be strange behavior of scipy.interpolate.interp2d. I do not understand what the problem is, and I will be happy for any help or tips.

import numpy as np
from scipy.interpolate import interp2d

x = np.arange(10)
y = np.arange(20)
xx, yy = np.meshgrid(x, y, indexing = 'ij')
val = xx + yy
f = interp2d(xx, yy, val, kind = 'linear')

When I run this code, I get the following warning:

scipy / interpolate / fitpack.py: 981: RuntimeWarning: no more nodes can be added because the number of B-spline coefficients already exceeds the number of data points m. Likely causes: s or m are too small. (fp> s) kx, ky = 1.1 nx, ny = 18.15 m = 200 fp = 0.000000 s = 0.000000
warnings.warn (RuntimeWarning (_iermess2 [ierm] [0] + _mess))

, interp2d , , . f , :

>>> f(1,1)
array([ 2.])

, , .

>>> f(1.1,1)
array([ 2.44361975])

, , . - ? Matlab, 1:1, , , , - .

(.. y = np.arange(10)), , , . , ( ), - .

+4
1

() , scipy.LinearNDInterpolator. . , , , , , .

import numpy as np
import itertools
from scipy.interpolate import LinearNDInterpolator

x = np.arange(10)
y = np.arange(20)
coords = list(itertools.product(x,y))
val = [sum(c) for c in coords]
f = LinearNDInterpolator(coords, val)

>>>f(1,1)
array(2.0)

>>> f(1.1,1)
array(2.1)
+1

Source: https://habr.com/ru/post/1622665/


All Articles