Kushagr Bansal
Kushagr Bansal

Reputation: 13

interpolation of arrays with multiple dimensions in python using scipy .

I have 2 arrays .

DEPTH = array([1945.0813, 1945.2337, 1945.3861, ..., 3089.7577, 
3089.9101,3090.0625])

DEPTH.shape = (7514,)

'CURVE_VALUES' = array([[  8.8783,  16.5181,      nan,  42.9207, 
   137.1404],
   [  8.8783,  16.4784,      nan,  42.2368, 137.8069],
   [  8.8783,  16.685 ,      nan,  41.3884, 138.402 ],
   ...,
   [     nan,      nan,      nan,      nan,      nan],
   [     nan,      nan,      nan,      nan,      nan],
   [     nan,      nan,      nan,      nan,      nan]])


   CURVE_VALUES.shape = (7514, 5)

How can i interpolate 'CURVE_VALUES' over 'DEPTH' such that if i have a new array 'NEW_DEP' = array([1950.1104, 1950.2628, 1950.4152, ..., 3089.91 , 3090.0624, 3090.2148])

I can find the respective CURVE_VALUES by interpolation .

I've tried using scipy.interpolate.interp1d for single dim but i want to interpolate nD array over a 1d array .

import numpy as np
from scipy import interpolate
x = np.arange(0, 10)
y = np.exp(-x/3.0)
f = interpolate.interp1d(x, y)

I expect the result to be of the same shape to be of : number of rows of NEW_DEP x number of cols of CURVE_VALUES

Upvotes: 1

Views: 1166

Answers (1)

Tarifazo
Tarifazo

Reputation: 4343

Multivariate interpolation is used when you have a (N,d) x points and (N,1) y points. What you are trying to do is the opposite. Try this:

interpolators = [interp1d(DEPTH, y_slice) for y_slice in CURVE_VALUES.T]
f = lambda x: np.array([i(x) for i in interpolators])

Upvotes: 2

Related Questions