python float对象不支持项赋值

2024-04-28 20:47:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行以下代码,但我收到错误消息“float”对象不支持项分配。我想要的输出是将这些计算的结果附加到向量Vi中

import numpy as np

MolWeight = [132, 320, 29, 45, 10]
Ci = 10 # g/L initial Concentration
Cf = 50*10**(-6) #M final Concentration
Vf = 100*10**(-6) #Litre final Volume
Vi = []
for i in range(len(MolWeight)):
    #How many moles of the compounds are there in the standard solution
    Mi = Ci/MolWeight[i] #M
    #this corresponds to the initial concentration of the standard     compound
    Ci = Mi #M/L
    #I calculate the volume to extract from the standard compound    solution, so to obtain the desired concentration 
    np.append.Vi[i] = (Cf*Vf)/Ci #L

Tags: ofthetoincinpstandardinitial
2条回答

这就是你要找的吗? 我认为问题出在整除和附加上

import numpy as np

MolWeight = [132.0, 320.0, 29.0, 45.0, 10.0]
Ci = 10.0 # g/L initial Concentration
Cf = 50*10**(-6) #M final Concentration
Vf = 100*10**(-6) #Litre final Volume
Vi = []
for i in range(len(MolWeight)):
    #How many moles of the compounds are there in the standard solution
    Mi = Ci/MolWeight[i] #M
    #this corresponds to the initial concentration of the standard     compound
    Ci = Mi  # M/L
    #I calculate the volume to extract from the standard compound    solution, so to obtain the desired concentration 
    # np.append.Vi[i] = (Cf * Vf) / Ci  # L
    Vi.append((Cf * Vf) / Ci )


print Vi

输出

^{pr2}$

你能做到的

Vi.append((Cf*Vf)/Ci) #L

输出:

^{pr2}$

相关问题 更多 >