Given two known 2D arrays (dimensions are time and position), dhdt_arr and dTsdt_arr, how can I generate some other 2D arrays from these faster than using nested for loops?
The arrays I would like to generate are named below, and have been setup like the known arrays:
dmdt_arr = np.zeros_like(dhdt_arr) #change in mass holdup
T_arr = np.zeros_like(dhdt_arr) # fluid temperature
m_hold_arr = np.zeros_like(dhdt_arr) # mass hold up
U_arr = np.zeros_like(dhdt_arr) # heat transfer coefficient array
The nested for loop I am using to generate the above arrays (assume the algebra is correct, the constants are known, and the functions I used are also known). I am just looking for a way to replace this structure with something faster, like a numpy vectorized approach):
for i in range(time.shape[0]): #iteratung through 2D array time x #positions
for j in range(n): #yep
T = temperature(h_arr[j,i],P)
dmdt_arr[j, i] = dhdt_arr[j, i] * dpdh(h_arr[j, i], P) * V
T_arr[j,i] = T
m_hold_arr[j, i] = mass(h_arr[j, i], P)
U_arr[j,i] = mAlumina*CP_ALUMINA*dTsdt_arr[j,i]/(sa*(T_arr[j,i] - Ts_arr[j,i]))
How can these same arrays be generated in a way that is faster than a nested for loop?