2014-06-10 158 views
0

我遇到一個問題,我的數組只填充了計算值的最後一個空格。我的代碼如下:數組只填充最後一個值

c_volume = 4.45e-5                
c_flow_rate = 1.67e-6               

acr = c_flow_rate/c_volume 

t1 = [3600.0,18000.0, 36000.0] 
air_conc_t1 = [6.42404968e+02, 2.74977722e+02, 1.45282562e+02] 


t2 = [7200.0, 21600.0, 39600.0] 
air_conc_t2 = [4.53346985e+02, 2.41359268e+02, 1.28038071e+02] 

=============================================================== 

n_calc = np.zeros((len(t1),1), dtype='f') 

def n(t1, air_conc_t1, t2, air_conc_t2): 
    return (1/(t2-t1))*(np.log(air_conc_t1/air_conc_t2))       

for i in range(len(t1)): 
    n_calc[i] = n(t1[i], air_conc_t1[i], t2[i], air_conc_t2[i]) 

=============================================================== 

calc_f1 = np.zeros((len(t1),1), dtype='f') 
calc_f2 = np.zeros((len(t1),1), dtype='f') 
calc_N = np.zeros((len(t1),1), dtype='f') 

def f1(acr, n_calc): 
    return (acr+n_calc)/n_calc              

calc_f1[i] = f1(acr, n_calc[i]) 

def f2(acr, n_calc): 
    return (acr-n_calc)/n_calc             

calc_f2[i] = f2(acr, n_calc[i]) 

def N(R, calc_root, m_thickness, calc_f1, calc_f2): 
    return (2*R*np.tan(calc_root*m_thickness))/(calc_root*m_thickness* 
     (calc_f1+calc_f2*calc_root*m_thickness*((1/np.tan(calc_root\ 
     *m_thickness))+np.tan(calc_root*m_thickness)))) 

for i in xrange(len(t1)): 
    calc_N[i] = N(R, calc_root[i], m_thickness, calc_f1[i], calc_f2[i])   

print calc_f1 
print calc_f2 
print calc_N 

我越來越有如下印刷:

[[ 0.  ] 
[ 0.  ] 
[ 1070.23657227]] 
[[ 0.  ] 
[ 0.  ] 
[ 1068.2364502]] 
[[    inf] 
[    inf] 
[ 3.55326119e-06]] 

我不知道爲什麼數組的前兩個值沒有被填滿,但最後一個是。我已經通過手工計算並獲得了數值。

我很新的編程,所以任何幫助,將不勝感激。

感謝,

巴蒂爾

回答

1

到f1和f2您的來電是不是在一個循環。請注意,循環中包含與縮進級別相同的所有內容。

試試這個:

for i in xrange(len(t1)): 
    calc_f1[i] = f1(acr, n_calc[i]) 
    calc_f2[i] = f2(acr, n_calc[i]) 
    calc_N[i] = N(R, calc_root[i], m_thickness, calc_f1[i], calc_f2[i])   

print calc_f1 
print calc_f2 
print calc_N 
+0

謝謝你這個工作。 – ShaneCan

1

calc_f1[i] = f1(acr, n_calc[i]) 

calc_f2[i] = f2(acr, n_calc[i]) 

任何for環路外(也許是與凹痕唯一的問題)。

+0

謝謝你這個工作。 – ShaneCan