Suppose I have data that depends on 4 variables: a, b, c and d. I want interpolate to return a 2D array which corresponds to a single value of a and b, and an array of values for c and d. However, The array size need not be the same. To be specific, my data comes from a transistor simulation. The current depends on 4 variables here. I want to plot a parametric variation. The number of points on the parameter is a lot less than the number of points for the horizontal axis.
import numpy as np
from scipy.interpolate import interpn
arr = np.random.random((4,4,4,4))
x1 = np.array([0, 1, 2, 3])
x2 = np.array([0, 10, 20, 30])
x3 = np.array([0, 10, 20, 30])
x4 = np.array([0, .1, .2, .30])
points = (x1, x2, x3, x4)
The following works:
xi = (0.1, 9, np.transpose(np.linspace(0, 30, 4)), np.linspace(0, 0.3, 4))
result = interpn(points, arr, xi)
and so does this:
xi = (0.1, 9, 24, np.linspace(0, 0.3, 4))
result = interpn(points, arr, xi)
but not this:
xi = (0.1, 9, np.transpose(np.linspace(0, 30, 3)), np.linspace(0, 0.3, 4))
result = interpn(points, arr, xi)
As you can see, in the last case, the size of the last two arrays in xi is different. Is this kind of functionality not supported by scipy or am I using interpn incorrectly? I need this create a plot where one of the xi's is a parameter while the other is the horizontal axis.


interpncorrectly... I'm assuming thatpointsrepresents your grid, i.e., the "sampling points" in each of your four dimensions for the values that you know.arrholds these known values. But making them random means it's hard to check whether or not the interpolation is working. Try making them all equal instead, or better yet, linear in each of the four dimensions.xishould be the coordinates of the points at which you want to know the values ofarr.xishould be an array with k rows, for k points, and 4 columns (4D data). - Praveennp.transpose(np.linspace(0, 30, 3))does not make it into a column vector. Read about 1D arrays in numpy. You need to introduce a new dimension, so usenp.linspace(0, 30, 3)[:, np.newaxis]instead. But in this case, you don't need this, as I show in my answer. - Praveen