如何使用不同的列进行for循环迭代
How to use different columns for for loop iteration
所以我想进行一次迭代 (a)
我有一个 excel sheet,其中迭代已经编程,我现在想在 python 3 spyder 中做同样的事情。
我决定从外部计算第一行。迭代现在应该是这样的:
da,air core diameter (2,1) 有输入 t_new (1,5), delta p, spray pressure (2,2) 有输入 da,air core diameter (2,1), t_new (2,5) 对于给定的迭代次数,具有输入增量 p、喷雾压力 (2,2) 等。
到目前为止,我的代码如下所示(其他所有内容都已事先正确定义):
a = [b for b in range(14)] # number of iterations -1
arr = np.array([[da_iter], [ps_iter], [t_mod_iter]]).reshape(1,3) # external calculated values first row
arr_zeros = np.zeros([len(a), 3]) # filling array with 0's based on iteration number
arr_iter = np.vstack((arr, arr_zeros)) #iteration array with 1st row calculated values
i = 0 #row index
j = 0 #column index
for i in range(len(arr_iter)):
np.append(arr_iter, do_in-2*arr_iter[i,j+2]) #calculating new da out of t_mod
np.append(arr_iter, ml**2*gs*0.5*pl*((dsc/(2*pl*(hsc*din*arr_iter[i+1,j]/2)))**2+(1/(pl*(ao-np.pi/4*arr_iter[i+1,j]**2)))**2)) #calculating new ps out of new da
np.append(arr_iter, k*(1738.7*ul**2-79.898*ul+2.0122)*((do_in*ml*ul)/(pl*arr_iter[i+1,j+1]))**0.25) #calculation new t_new out of spray pressure
i = i+1
print(arr_iter)
但这似乎无法正常工作,因为我只是像以前一样离开 arr_iter。不幸的是,我也没有发现如何使用 for 循环迭代更改行的有用方法。
有人知道如何去做或看到我在循环中的错误吗?
非常感谢您
首先,您不需要 i=i+1
,因为 for 循环 已经这样做了。
其次,我想你想替换 arr_iter
中的零,所以在 for 循环中,你应该写类似
的东西
np.append(arr_iter[i, j], 2nd_variable)
或者,您可以简单地执行以下操作来更新 arr_iter
矩阵,而不是 append
。
arr_iter[i][j] = new_variable
所以我想进行一次迭代 (a)
我有一个 excel sheet,其中迭代已经编程,我现在想在 python 3 spyder 中做同样的事情。
我决定从外部计算第一行。迭代现在应该是这样的: da,air core diameter (2,1) 有输入 t_new (1,5), delta p, spray pressure (2,2) 有输入 da,air core diameter (2,1), t_new (2,5) 对于给定的迭代次数,具有输入增量 p、喷雾压力 (2,2) 等。
到目前为止,我的代码如下所示(其他所有内容都已事先正确定义):
a = [b for b in range(14)] # number of iterations -1
arr = np.array([[da_iter], [ps_iter], [t_mod_iter]]).reshape(1,3) # external calculated values first row
arr_zeros = np.zeros([len(a), 3]) # filling array with 0's based on iteration number
arr_iter = np.vstack((arr, arr_zeros)) #iteration array with 1st row calculated values
i = 0 #row index
j = 0 #column index
for i in range(len(arr_iter)):
np.append(arr_iter, do_in-2*arr_iter[i,j+2]) #calculating new da out of t_mod
np.append(arr_iter, ml**2*gs*0.5*pl*((dsc/(2*pl*(hsc*din*arr_iter[i+1,j]/2)))**2+(1/(pl*(ao-np.pi/4*arr_iter[i+1,j]**2)))**2)) #calculating new ps out of new da
np.append(arr_iter, k*(1738.7*ul**2-79.898*ul+2.0122)*((do_in*ml*ul)/(pl*arr_iter[i+1,j+1]))**0.25) #calculation new t_new out of spray pressure
i = i+1
print(arr_iter)
但这似乎无法正常工作,因为我只是像以前一样离开 arr_iter。不幸的是,我也没有发现如何使用 for 循环迭代更改行的有用方法。
有人知道如何去做或看到我在循环中的错误吗? 非常感谢您
首先,您不需要 i=i+1
,因为 for 循环 已经这样做了。
其次,我想你想替换 arr_iter
中的零,所以在 for 循环中,你应该写类似
np.append(arr_iter[i, j], 2nd_variable)
或者,您可以简单地执行以下操作来更新 arr_iter
矩阵,而不是 append
。
arr_iter[i][j] = new_variable