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

Charles R Harris charlesr.harris at gmail.com
Thu Sep 5 21:33:55 EDT 2013


On Thu, Sep 5, 2013 at 3:40 PM, <josef.pktd at gmail.com> wrote:

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

The rows are views, so that is expected. What is unexpected is that the
void/string scalars are also views.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130905/ee104043/attachment.html>


More information about the NumPy-Discussion mailing list