2014-01-15 3 views
1

SciPy.interpolate의 interp1d로 작업하려고합니다. 같은 크기의 두 배열 (filtered_mass 및 integrated_column)을 "연결"했지만 여전히 배열의 크기가 같아야한다는 ValueError를 제공합니다. 어떻게 그럴 수 있죠?SciPy 보간 ValueError : x 및 y 배열은 보간 축을 따라 길이가 같아야합니다.

def interp_integrated_column(self, definition): 
    ''' (string) -> interpolated_function(mass) 
    This functions output the interpolated value of the integrated columns 
    as function of the mass of the WIMP (mDM) 
    ''' 
    print self.filtered_mass_array 
    print "len(filtered_mass)", len(self.filtered_mass_array) , "len(integrated_column)", len(self.integrated_columns_values[definition]) 
    print self.integrated_columns_values[definition] 
    interpolated_values = interp1d(self.filtered_mass_array, self.integrated_columns_values[definition]) 
    return interpolated_values 

이 오류 메시지입니다 :

나는이 부분에서 사용하고 코드를 모두 길이 (62)에게이

[5.0, 6.0, 8.0, 10.0, 15.0, 20.0, 25.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 180.0, 200.0, 220.0, 240.0, 260.0, 280.0, 300.0, 330.0, 360.0, 400.0, 450.0, 500.0, 550.0, 600.0, 650.0, 700.0, 750.0, 800.0, 900.0, 1000.0, 1100.0, 1200.0, 1300.0, 1500.0, 1700.0, 2000.0, 2500.0, 3000.0, 4000.0, 5000.0, 6000.0, 7000.0, 8000.0, 9000.0, 10000.0, 12000.0, 15000.0, 20000.0, 30000.0, 50000.0, 100000.0] 
len(filtered_mass) 62 len(integrated_column) 62 
[[2.8855960615102004e-05], [4.0701386519793902e-05], [6.6563800907013242e-05], [0.0001006393622421269], [0.00019862657113084296], [0.00032843266928887332], [0.00046438711039847576], [0.00060420820026262198], [0.00091858847275374405], [0.0012828446411529174], [0.0016307748004155418], [0.0020049092489578773], [0.0023859804990953733], [0.0027809435562397089], [0.0031914945950108709], [0.0036198713189993367], [0.004049356593219729], [0.058652386100581579], [0.080971818217450073], [0.10330986231789899], [0.13710341994459613], [0.20188314005754618], [0.2891914189026335], [0.37721295733783522], [0.47493929411417846], [0.57539389630897464], [0.70805980165022075], [0.85872215884312952], [1.0664252638663609], [1.2783399280844934], [1.564710616680836], [2.0375181832882485], [2.5037792909103884], [2.9693614352642328], [3.4461139299681416], [3.9753240755452568], [4.5112890074931942], [5.0575238552577968], [5.6116617190278557], [6.75034712149598], [7.9290625424458492], [9.1455816114675219], [10.393026346405367], [14.442148067840661], [18.539929482157905], [22.594593494117799], [28.852213268263831], [39.804824036584456], [51.348027754488449], [83.695041150108111], [118.92653801185628], [155.17895505284363], [192.83930746140334], [231.78928736553948], [271.95372644243321], [313.16712050353419], [398.50142684880342], [532.55760945531256], [768.84170621340957], [1276.9057251660611], [2387.368055624514], [5476.4080305101643]] 
Traceback (most recent call last): 
    File "data_mining.py", line 8, in <module> 
    e_int = nu_e.interp_integrated_column('e') 
    File "/home/ohm/projects/mucalc/PPPC4DMID_Reader.py", line 121, in interp_integrated_column 
    interpolated_values = interp1d(self.filtered_mass_array, self.integrated_columns_values[definition]) 
    File "/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py", line 278, in __init__ 
    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. 
+0

y를 x의 길이 무엇인가를 보간 축을 따라 배열? – mhlester

+0

이것은 62입니다 (이것들은 맨 위에 인쇄 한 len()입니다) – Ohm

+0

numpy 배열입니까? 그렇다면, 그들은 같은 모양을 가지고 있습니까? – M4rtini

답변

3

당신의 두리스트가 있지만, 그들은 다른 모양 해석이 같은 NumPy와 배열 :

>>> a = [5.0, 6.0, 8.0, 10.0, 15.0, 20.0, 25.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 180.0, 200.0, 220.0, 240.0, 260.0, 280.0, 300.0, 330.0, 360.0, 400.0, 450.0, 500.0, 550.0, 600.0, 650.0, 700.0, 750.0, 800.0, 900.0, 1000.0, 1100.0, 1200.0, 1300.0, 1500.0, 1700.0, 2000.0, 2500.0, 3000.0, 4000.0, 5000.0, 6000.0, 7000.0, 8000.0, 9000.0, 10000.0, 12000.0, 15000.0, 20000.0, 30000.0, 50000.0, 100000.0] 
>>> b = [[2.8855960615102004e-05], [4.0701386519793902e-05], [6.6563800907013242e-05], [0.0001006393622421269], [0.00019862657113084296], [0.00032843266928887332], [0.00046438711039847576], [0.00060420820026262198], [0.00091858847275374405], [0.0012828446411529174], [0.0016307748004155418], [0.0020049092489578773], [0.0023859804990953733], [0.0027809435562397089], [0.0031914945950108709], [0.0036198713189993367], [0.004049356593219729], [0.058652386100581579], [0.080971818217450073], [0.10330986231789899], [0.13710341994459613], [0.20188314005754618], [0.2891914189026335], [0.37721295733783522], [0.47493929411417846], [0.57539389630897464], [0.70805980165022075], [0.85872215884312952], [1.0664252638663609], [1.2783399280844934], [1.564710616680836], [2.0375181832882485], [2.5037792909103884], [2.9693614352642328], [3.4461139299681416], [3.9753240755452568], [4.5112890074931942], [5.0575238552577968], [5.6116617190278557], [6.75034712149598], [7.9290625424458492], [9.1455816114675219], [10.393026346405367], [14.442148067840661], [18.539929482157905], [22.594593494117799], [28.852213268263831], [39.804824036584456], [51.348027754488449], [83.695041150108111], [118.92653801185628], [155.17895505284363], [192.83930746140334], [231.78928736553948], [271.95372644243321], [313.16712050353419], [398.50142684880342], [532.55760945531256], [768.84170621340957], [1276.9057251660611], [2387.368055624514], [5476.4080305101643]] 
>>> np.asarray(a).shape 
(62,) 
>>> np.asarray(b).shape 
(62, 1) 
당신은 두 번째 배열 1D, 2D하지 수 있도록 할 것입니다

. 이 NumPy와에서이 작업을 수행하려면 대략 천조 가지가 있지만 하나의 단일 차원 축 제거 .squeeze(), 사용하는 것입니다

>>> a = np.asarray(a) 
>>> b = np.asarray(b).squeeze() 
>>> b.shape 
(62,) 

후 :

>>> from scipy.interpolate import interp1d 
>>> i = interp1d(a,b) 
>>> i(2123) 
array(31.546555517270704)