'1D cubic interpolation unequal arrays using Numpy and Scipy

I need to perform a cubic 1D interpolation over a number of large arrays. I would normally use pandas but I am struggling to use pandas for repeating x-values. From what I understand this can be achieved using numpy. However, I am struggling to setup the arrays correctly. For each x-value there are 50,000 y-values. I cannot repeating this as an example. The example below is for less values but I am hoping to extend it to greater values.

The first entry for the interpolation is (x1, (y1,y0)) and the last entry is (x4,(y4,y10)). Firstly, I do not think I have set the arrays up correctly and secondly, I do not think I am using the interpolation function correctly.

import numpy as np
from scipy import interpolate

# setting up x-arrays
x1 = [10] * 10
x2 = [20] * 10
x3 = [30] * 10
x4 = [40] * 10

x_array_tuple = (x1,x2,x3,x4)
x_arrays = np. vstack(x_array_tuple)

# import y-arrays

y1 = [0,1,2,3,4,5,6,7,8,9]
y2 = [0,1,2,3,4,5,6,7,8,9]
y3 = [0,1,2,3,4,5,6,7,8,9]
y4 = [0,1,2,3,4,5,6,7,8,9]

y_array_tuple = (y1,y2,y3,y4)
y_arrays = np. vstack(y_array_tuple)

# interpolation
i_func = interpolate.interp1d(x_arrays,y_arrays, kind='cubic', fill_value='extrapolation') # the first entry is (x1, (y1,y0)); the last entry is (x4,(y4,y10))

This is the error message I get:

raise ValueError("x and y arrays must be equal in length along "

ValueError: x and y arrays must be equal in length along interpolation axis.

How do I perform this interpolation?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source