简体   繁体   English

在python中插入值矩阵

[英]interpolating a matrix of values in python

I have the following .txt file:

elevation   [1] inpol1       [2] inpol2       [3] RL(L1)       [4] RL(L2)       [5] LR(L1)       [6] LR(L2)
90.0,   -6.67107685717,   -2.44901761488,   -23.57314833,   -16.97583667,   -21.77855833,   -19.14620333,   
80.0,   -6.8610001598,   -2.55403460547,   -23.28653167,   -17.77932667,   -21.98888667,   -18.62304333,   
70.0,   -7.26186588862,   -2.9273149233,   -23.36461833,   -18.56328833,   -22.90425333,   -19.83013333,   
60.0,   -8.12320485689,   -3.92112857734,   -26.12222167,   -18.67996333,   -22.35199667,   -21.07369833,   
50.0,   -8.79551120253,   -4.78951507462,   -25.77091833,   -20.15670667,   -22.80505,   -19.24572,   
40.0,   -9.7150274851,   -5.74026771244,   -26.13789833,   -19.492935,   -24.116195,   -18.91178833,   
30.0,   -12.4733143154,   -7.38382695233,   -29.59175167,   -20.10266833,   -26.68595167,   -16.59469,   
20.0,   -15.3636359113,   -8.17039424613,   -28.16000167,   -18.59742333,   -29.06789167,   -16.16085667, 
10.0,   -18.4342503347,   -8.1905188993,   -24.938385,   -18.42761667,   -25.16124333,   -16.52676833,    
0.0,   -18.1632600571,   -9.01468419945,   -26.55651833,   -17.22991,   -24.81285167,   -14.60796,   
-10.0,   -16.7133867094,   -11.2860511308,   -23.03011,   -14.87516333,   -25.25885667,   -12.8514,   
-20.0,   -16.9661747422,   -14.9817503484,   -21.28522167,   -13.41128833,   -22.79150667,   -12.05261,   
-30.0,   -19.0849332428,   -25.0207809175,   -22.19593333,   -11.657085,       -21.78081833,   -11.15619333,   
-40.0,   -23.0413759193,   -27.6812084151,   -21.06287,   -10.79255333,   -21.43039167,   -11.43889667,   
-50.0,   -27.2608901323,   -26.008410352,   -20.72646333,   -10.53535783,   -19.86449333,   -11.257135,   
-60.0,   -32.3277829825,   -26.3760335651,   -19.491665,   -10.0824975,   -18.044145,   -9.58142683,   
-70.0,   -31.9688083301,   -24.6389964298,   -17.26466667,   -8.98763067,   -17.47626,   -8.15476567,   
-80.0,   -31.8190661767,   -22.2776308495,   -16.27771,   -7.96193283,   -16.95944667,   -7.04178467,   
-90.0,   -30.1752513951,   -21.8107054104,   -15.40699222,   -7.50867589,   -15.90784333,   -6.01267233,

I want to create a piece of code that interpolates the values [1] inpol1, [2] inpol2, [3] RL(L1), [4] RL(L2), [5] LR(L1), [6] LR(L2).我想创建一段代码来插入值 [1] inpol1, [2] inpol2, [3] RL(L1), [4] RL(L2), [5] LR(L1), [6] LR (L2)。 I think I have to use the interp1d function from scipy.interpolate, but i dont know how to perform this on my txt file.我想我必须使用 scipy.interpolate 中的 interp1d 函数,但我不知道如何在我的 txt 文件上执行此操作。

EDIT: sorry i should say that for any given elevation i need the values interpolating.编辑:抱歉,我应该说,对于任何给定的海拔,我都需要内插值。

Does anyone know how to carry out this task?有谁知道如何执行这项任务? Note: the values are decibel values, ie they are logarithmic.注意:这些值是分贝值,即它们是对数的。

so far I have到目前为止我有

ncal=open('H:/Uni Work/stage 3/Dissertation/Data/newcalibrations.txt')
ncal=ncal.readlines()[1:]
for x in ncal:
    x=x.split(',')
    elevations_for_calibration = x[0]
    calibration_values=x[1:]
    calibration_function = interpolate.interp1d(elevations_for_calibration,calibration_values)

but i know that this will not work.但我知道这行不通。

I will make something like that :我会做这样的事情:

import numpy as np

ncal = np.genfromtxt('H:/Uni Work/stage 3/Dissertation/Data/newcalibrations.txt', dtype = float, delimiter = ',' , names=True, skip_header=0 )
ncal = ncal.readlines()

interpolation = np.interp(...)

You might use np.interp in order to make that.您可以使用np.interp来实现。 I'm on my mobile, so I can't launch it, but try to focus on np.interp numpy module ;)我在我的手机上,所以我无法启动它,但尽量专注于 np.interp numpy 模块;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM