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

Jonathan Helmus jjhelmus at gmail.com
Thu Sep 5 14:57:05 EDT 2013

On 09/05/2013 01:50 PM, Fernando Perez wrote:
> On Thu, Sep 5, 2013 at 11:43 AM, Charles R Harris
> <charlesr.harris at gmail.com> wrote:
>> Oh, nice one ;) Should be fixable if you want to submit a patch.
> Strategy? One option is to do, for structured arrays, a shuffle of the
> indices and then an in-place
> arr = arr[shuffled_indices]
> But there may be a cleaner/faster way to do it.
> I'm happy to submit a patch, but I'm not familiar enough with the
> internals to know what the best approach should be.
> Cheers,
> f

Fixing the shuffle function can be done by adding a check to see if x[0] 
is of type numpy.void on line 4429 of numpy/random/mtrand/mtrand.pyx and 
using the top if block of code which uses a buffer for element swapping 
if it is.  But it wouldn't fix the problem with swapping of records 
array elements which is the real problem.

     - Jonathan Helmus

More information about the NumPy-Discussion mailing list