python float对象不支持项赋值

标签 python object variable-assignment

我正在运行以下代码,但收到错误消息“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

最佳答案

你可以这样做

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

输出:

Vi
[6.599999999999998e-08,
 2.1119999999999998e-05,
 0.0006124799999999999,
 0.027561599999999995,
 0.27561599999999997]

关于python float对象不支持项赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46520399/

相关文章:

python - 条件分配

c++ - C++ 正十进制整数的递归函数数字逆序

python - 如何知道 pexpect 命令实际运行?

python - python中的同时模拟

python - 使用列表理解查找列表中的元素,其中另一个列表中的所有元素都是因子

javascript - Javascript 对象中的函数数组

python - 从python中的对象列表中删除对象

python - django-tables2 复选框列名

javascript - 不将函数声明为另一个自定义函数的原型(prototype)的用例?

编译器可以优化嵌套循环吗?