I am retrieving time-series values using 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.
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 . 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
:
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
)
print(targetmodel[:,1].tolist())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.