2017-10-02 1 views
1

Je cours le code suivant, mais le message d'erreur "float" ne prend pas en charge l'affectation d'élément. Ma sortie désirée est d'ajouter les résultats de ces calculs dans le vecteur ViL'objet float python ne prend pas en charge l'affectation d'élément

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 
+0

@Evert append accolade est erroné 'Vi [i] .append (Cf * Vf/Ci)'. Mais bonne suggestion. –

Répondre

1

vous pouvez juste faire

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

sortie:

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

était ce que vous cherchez? Je pense que le problème était la division int et append

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 

sortie

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