我写了一个代码,我想用它来减少测量数据。为此,我遍历了 30 组测量数据。在每次迭代中,我使用fsolve求解一组三个非线性方程。这给了我一个包含三个值的数组,然后进一步处理这些值(在下面的示例中lbda,alp, bta, dlt, q, N)。我可以打印结果,但需要在 30 x 6 数组中收集所有 30 个周期的数据,以进行一些统计(即 6 个变量中的每一个的 np.mean)。在每次迭代结束时,我已经尝试了对我来说最明显的函数np.append, np.vstack,np.concatenates但这只会给我一个 1 x 6 数组,其中仅包含最后一个迭代步骤,而不是包含所有 30 次迭代的所需数组脚步。# loading data above m1 = data_arr_blkcorr [:,4] / data_arr_blkcorr [:,2]m2 = data_arr_blkcorr [:,5] / data_arr_blkcorr [:,2] m3 = data_arr_blkcorr [:,7] / data_arr_blkcorr [:,2]N=-1while (N<29): N = N+1 T1 = 79.744440299369400 T2 = 4.756431967877120 T3 = 195.146815878103000 T4 = 1.333609171398 T5 = 0.540566631391 T6 = 1 T7 = 1.731261585620 T_all = np.array([T4, T5, T6, T7, T1, T2, T3]) n1 = 0.598169735 n2 = 1.509919737 n3 = 0.600477235 n4 = 0.9364071191658 n5 = 0.5815716133216 n6 = 1 n7 = 1.0455228260642 n_all = np.array([n4, n5, n6, n7, n1, n2, n3]) I1 = 94.905838 I2 = 96.906018 I3 = 97.905405 I4 = 99.907473 I5 = 91.90681 I6 = 93.90509 I7 = 95.90468# some definition of variables here A11 = T1-n1 A12 = T2-n2 A13 = T3-n3 A21 = -n1*P1 A22 = -n2*P2 A23 = -n3*P3 A31 = m1[N] * P1 A32 = m2[N] * P2 A33 = m3[N] * P3 b11 = m1[N] - n1 b12 = m2[N] - n2 b13 = m3[N] - n3# some definition of variables here T = np.array ([T1, T2, T3]) n = np. array([n1, n2, n3]) m = np.array([m1[N], m2[N], m3[N]]) P = np.array([P1, P2, P3]) def F(x): return x[0]*T + (1-x[0])*n*np.exp(-x[1]/(1-x[0])*P) - m*np.exp(-x[2]*P) y = fsolve(F, guess) lbda = y[0] alp = y[1]/(1-y[0]) bta = y[2] dlt = (np.exp(-alp*P2)-1)*1000 N_all = n_all * np.exp(-alp*P_all) q = (1 + (1 - lbda) / lbda * np.sum(N_all) / np.sum(T_all))**(-1) print (lbda, alp, bta, dlt, q, N) 浏览帖子我也使用过这个(根据 Koke Cacao 提供的建议):data_sum = Nonenew_data = [lbda, alp, bta, dlt, q, N]data_sum = np.append([data_sum], new_data) if data_sum is not None else new_dataprint(data_sum)
2 回答
胡子哥哥
TA贡献1825条经验 获得超6个赞
尝试在您的 while 循环之外创建一个空列表,然后附加该数组。
solution = []
while n < 29:
#your code here
solution.append([lbda, alp, bta, dlt, q, N])
繁花不似锦
TA贡献1851条经验 获得超4个赞
您应该在 while 循环范围之外声明一个空列表,然后在每次迭代时附加到它:
result = []
while(N<29):
# calculate something
result.append(your_data)
print(result) # that will give you all the data that you got from each Iteration
添加回答
举报
0/150
提交
取消