mardi 22 mars 2016

Python list(or dict) of random list

I would create a list or a dictionnary "p0" containing lists with random numbers at a particular index. I do not understand what happens in this short code:

import numpy as np

p0={}
a=[0,0,0]

for i in range(10):
    a[1]= np.random.uniform(0,i) 
    print a
    p0[i] = a 
    print p0[i]
print "\n final p0: ",p0

the final p0 only contains 10 times the last iteration result... and is different from the previous (in the loop) p0.




Aucun commentaire:

Enregistrer un commentaire