[英]Converting time-series values into a python list
I am retrieving time-series values using odeint function.我正在使用odeint function 检索时间序列值。 It solves a system of differential equation.
它解决了一个微分方程组。
measurement_times = np.arange(0, 12,.1)
init = [.1,.1,.1,.1,.1]
def tar(y, measurement_times):
T, U, V,W,I = y
dT = 0.9*I*10.24 - T*0.0012
dU = V*T*0.0154 - U*1*0.81
dV = W*0.1*0.12 + U*1*0.81 - V*1.64 - V*T*0.015
dW= V*1.64 + 0.7*1*0.47 - W*0.1*0.12 - W*U*1591.5*1
dI= T*0.0012 + 0.8*U*1410.79*1- 0.9*I*10.24 - I*1*1934.77*1
return dT, dU, dV, dW, dI
targetmodel= sp.integrate.odeint(tar, init, measurement_times)
If I print the values of dU it gives me some values like mentioned below.如果我打印dU的值,它会给我一些如下所述的值。
for g in targetmodel:
print(str(g[1]));
--------------------------------
0.1
0.09223727996210558
0.0850835704105759
0.07849011448256649
What I want is to convert the values into a list and assign that list to the variable data .我想要的是将值转换为列表并将该列表分配给变量data 。 Currently, I am doing it manually by copying the values and assigning to the variable data
目前,我通过复制值并分配给变量数据来手动完成
Manual way
data = [0.1,0.09223727996210558,0.0850835704105759,0.078490114482]
I would like to find a way to do it automatically without assigning the values to variable data manually.我想找到一种自动执行此操作的方法,而无需手动将值分配给可变数据。 Thanks
谢谢
I hope that helps you希望对你有帮助
data = []
for g in targetmodel:
data.append(g[1])
add the following code after targetmodel
:在
targetmodel
之后添加以下代码:
since the tagetmodel
is of ndarray
you can use basic numpy slicing to tell it to select all rows and column at index 1.(Index start at 0
)因为
tagetmodel
是ndarray
,你可以使用基本的numpy切片告诉它select索引1处的所有行和列。(索引从0
开始)
print(targetmodel[:,1].tolist())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.