Numpy Array of Sets

LJ luisjosenovoa at gmail.com
Sun May 25 08:29:49 EDT 2014


Wolfgang, thank you very much for your reply.

Following the example in the link, the problem appears:

>>> A = [[0]*2]*3
>>> A
[[0, 0], [0, 0], [0, 0]]
>>> A[0][0] = 5
>>> A
[[5, 0], [5, 0], [5, 0]]

Now, if I use a numpy array:

>>> d=array([[0]*2]*3)
>>> d
array([[0, 0],
       [0, 0],
       [0, 0]])
>>> d[0][0]=5
>>> d
array([[5, 0],
       [0, 0],
       [0, 0]])


What is the difference here?

Thank you,



More information about the Python-list mailing list