0
我有一個需要使用第一列的文件。其餘的列需要與第一列進行整合。比方說我的文件看起來像這樣:使用數據文件中的多列
100 1.0 1.1 1.2 1.3 0.9
110 1.8 1.9 2.0 2.1 2.2
120 1.8 1.9 2.0 2.1 2.2
130 2.0 2.1 2.3 2.4 2.5
我可以寫一段代碼,是以第二列,並與第一那麼第三集成和整合相對於第一等?對於我的代碼有:
import scipy as sp
first_col=dat[:,0] #first column from data file
cols=dat[:,1:] #other columns from data file
col2 = cols[:,0] # gets the first column from variable cols
I = sp.integrate.cumtrapz(col2, first_col, initial = 0) #integration step
這僅適用於從變量山坳中的第一行,但是,我不想寫這爲所有其它列,它看起來討論(的思想它讓我發抖)。我看到過類似的問題,但一直未能將答案與我的答案聯繫起來,而那些差不多相同的答案卻含糊不清。有任何想法嗎?
你可以使用'genfromtxt',然後自己執行所有的集成作爲替代 – Matthew
什麼參數可以讓我循環訪問列? – skitt1z1
如果ive明白你想要的是什麼,你想要在幾個列上應用相同的集成,所以'data = sp.genfromtxt(「file.txt」);爲col in數據[0]:;集成(data [:,0],data [:,col]),其中'integrate'是一個def函數。 (雖然答案似乎是做你想要的,而不必自己寫!) – Matthew