[Numpy-discussion] A bug in numpy.random.shuffle?

josef.pktd at gmail.com josef.pktd at gmail.com
Thu Sep 5 17:40:00 EDT 2013


>> >
>> > In [4]: x[0], x[1] = x[1], x[0]

Is this ever predictable?
sounds to me like the inplace question a few days ago
result depends on the underlying iterator

>>> a = np.arange(5*3).reshape((5,3), order='F')
>>> a
array([[ 0,  5, 10],
       [ 1,  6, 11],
       [ 2,  7, 12],
       [ 3,  8, 13],
       [ 4,  9, 14]])
>>> b = a[::-1]
>>> b
array([[ 4,  9, 14],
       [ 3,  8, 13],
       [ 2,  7, 12],
       [ 1,  6, 11],
       [ 0,  5, 10]])
>>> b[0], b[1] = b[1], b[0]
>>> b
array([[ 3,  8, 13],
       [ 3,  8, 13],
       [ 2,  7, 12],
       [ 1,  6, 11],
       [ 0,  5, 10]])
>>> a
array([[ 0,  5, 10],
       [ 1,  6, 11],
       [ 2,  7, 12],
       [ 3,  8, 13],
       [ 3,  8, 13]])

The example works as "expected" if a is 1d

Josef



More information about the NumPy-Discussion mailing list