[Numpy-discussion] A bug in numpy.random.shuffle?
Jonathan Helmus
jjhelmus at gmail.com
Thu Sep 5 14:35:14 EDT 2013
On 09/05/2013 01:29 PM, Warren Weckesser wrote:
>
>
> On Thu, Sep 5, 2013 at 2:11 PM, Fernando Perez <fperez.net at gmail.com
> <mailto:fperez.net at gmail.com>> wrote:
>
> Hi all,
>
> I just ran into this rather weird behavior:
>
> http://nbviewer.ipython.org/6453869
>
> In summary, as far as I can tell, shuffle is misbehaving when acting
> on arrays that have structured dtypes. I've seen the problem on 1.7.1
> (official on ubuntu 13.04) as well as master as of a few minutes ago.
>
> Is this my misuse? It really looks like a bug to me...
>
>
>
> Definitely a bug:
>
> In [1]: np.__version__
> Out[1]: '1.9.0.dev-573b3b0'
>
> In [2]: z = np.array([(0,),(1,),(2,),(3,),(4,)], dtype=[('a',int)])
>
> In [3]: z
> Out[3]:
> array([(0,), (1,), (2,), (3,), (4,)],
> dtype=[('a', '<i8')])
>
> In [4]: shuffle(z)
>
> In [5]: z
> Out[5]:
> array([(0,), (1,), (2,), (0,), (0,)],
> dtype=[('a', '<i8')])
>
>
>
> Nothing in the docstring suggests that it shouldn't work for
> structured dtypes.
>
> Warren
Looks to stemming from the fact that elements of records arrays cannot
be swapped:
In [1]: import numpy as np
In [2]: x = np.zeros(5, dtype=[('n', 'S1'), ('i', int)])
In [3]: x['i'] = range(5)
In [4]: print x
[('', 0) ('', 1) ('', 2) ('', 3) ('', 4)]
In [5]: x[0], x[1] = x[1], x[0]
In [6]: print x
[('', 1) ('', 1) ('', 2) ('', 3) ('', 4)]
This is with numpy 1.7.1
Cheers,
- Jonathan Helmus
>
>
>
>
> Cheers,
>
> f
>
> --
> Fernando Perez (@fperez_org; http://fperez.org)
> fperez.net-at-gmail: mailing lists only (I ignore this when swamped!)
> fernando.perez-at-berkeley: contact me here for any direct mail
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org <mailto:NumPy-Discussion at scipy.org>
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130905/66afed9d/attachment.html>
More information about the NumPy-Discussion
mailing list