Crash in np.random.shuffle

Issue #60 new
Miles Steele created an issue

This program uses np.random.shuffle on a multidimensional array and it crashes. It seems like in order to get the crash the main axis must have at least 2 elements and the array must be multidimensional.

#!/usr/bin/env python
# Python 2.7.13 (1aa2d8e03cdfab54b7121e93fda7e98ea88a30bf, Apr 04 2017, 12:21:42)
# [PyPy 5.7.1 with GCC 6.3.0] on linux2
# pypy -m pip install git+https://bitbucket.org/pypy/numpy.git
import numpy as np

colors = np.zeros((2,1))
np.random.shuffle(colors)
print colors
Traceback (most recent call last):                                                 
  File "repro.py", line 8, in <module>                                             
    np.random.shuffle(colors)                                                      
  File "/home/miles/.pyenv/versions/pypy-5.7.1/site-packages/numpy/random/mtrand.py", line 3927, in shuffle                                                           
    buf[...] = x[j]                                                                
TypeError: 'long' object is not iterable                                           

Comments (1)

  1. Miles Steele reporter

    For anyone looking for a workaround in the meantime, this works

    colors = np.zeros((2,1))
    colors = colors[np.random.permutation(len(colors))]
    print colors
    
  2. Log in to comment