-2
該函數中的if語句在沒有向量化的情況下工作?如果numpy數組中的語句總是需要向量化
def K(T0,z,v):
for i in range(len(T0)-1):
GDens[i+1]=(Dens[i+1]-Dens[i])/(z[i+1]-z[i])
for i in range(len(T0)):
B[i]=(((ws/Dens0)*k0)**2)*np.exp(-2*alfa*z[i])-((g/Dens0)*GDens[i])
for i in range(len(T0)):
if B[i]>0:
kz[i]=((0.05*h1)**2)*np.sqrt(B[i])+kmin
else:
kz[i]=kmin
kfinal=kz
return kfinal