我有一个文件,我需要在其中使用第一列。其余列需要相对于第一列进行整合。假设我的文件如下所示:
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
这仅适用于变量 col 的第一行,但是,我不想为所有其他列写出来,它看起来像是在讨论(想到它让我颤抖)。我见过类似的问题,但无法将答案与我的答案联系起来,而那些或多或少相同的答案却含糊不清。有任何想法吗?