[Numpy-discussion] numpy.random.shuffle

Robert kxroberto at googlemail.com
Wed Nov 22 04:48:25 CST 2006


is this an error when shuffle doubles&looses items on a 2-d array? :

>>> r=arange(20)
>>> rr=ziparrays(r,r)  #numpy.vstack(*args).transpose()
>>> rr
array([[ 0,  0],
       [ 1,  1],
       [ 2,  2],
       [ 3,  3],
       [ 4,  4],
       [ 5,  5],
       [ 6,  6],
       [ 7,  7],
       [ 8,  8],
       [ 9,  9],
       [10, 10],
       [11, 11],
       [12, 12],
       [13, 13],
       [14, 14],
       [15, 15],
       [16, 16],
       [17, 17],
       [18, 18],
       [19, 19]])
>>> numpy.random.shuffle(rr)
>>> rr
array([[ 0,  0],
       [ 0,  0],
       [ 2,  2],
       [ 2,  2],
       [ 3,  3],
       [ 3,  3],
       [ 5,  5],
       [ 2,  2],
       [ 0,  0],
       [ 8,  8],
       [10, 10],
       [ 1,  1],
       [10, 10],
       [11, 11],
       [12, 12],
       [ 2,  2],
       [10, 10],
       [15, 15],
       [ 6,  6],
       [16, 16]])
>>>


on 1-d arrays it seems to be consistent as expected:


>>> numpy.random.shuffle(r)
>>> r
array([ 6,  1,  3, 17,  0, 11, 15,  7, 14, 10,  9,  2,  8, 12,  5,  4, 19,
       16, 13, 18])
>>> 



Robert



More information about the Numpy-discussion mailing list