如何使用定义的函数正确地使嵌套的for循环产生值数组

问题描述 投票:0回答:1

我已经定义了我的函数(分区函数partfunc_E,电离能chiI和温度T的函数),并且必须创建一个嵌套的for循环,首先遍历电离能(chiI,矢量)的值,然后内循环来评估离子在所有能量状态下的总和(此处使用5)。输出应为与chiI阵列中每个电离能相关的分配函数值的向量。

((根据我们的说明):对于10,000K的能量,使用钙的离子化能量和10,000K的温度应给出以下信息:

[ 1.45605581  1.45648718  1.45648849  1.45648849  1.45648849]

注意:对于所有状态,g = 1。

我不知道我做错了什么,但是我根本没有得到他们的期望,我得到的是长度为100的数组,并且数组中的所有值都相同。以下代码是我的尝试。

import matplotlib.pylab as plt
import numpy as np
from astropy import units as u
from astropy import constants as const
%matplotlib inline

k = const.k_B.to('eV*K**-1')
#print(k)

def partfunc_E(chiI,T):
    return g*np.exp(-(chiI/(k*T)))

chiI = [6.1131554, 11.871719, 50.91316, 67.2732, 84.34]*u.eV
T=(10000)*u.K
g= 1

partition_Ca = []

for i in chiI:
    for j in range(0,10,1):
        function = partfunc_E(chiI,T)
        partition_Ca.append(sum(partfunc_E(chiI,T)))
python-3.x function jupyter-notebook sum jupyter
1个回答
0
投票
您正在做这样的事情:
© www.soinside.com 2019 - 2024. All rights reserved.