[NumPy-Tickets] [NumPy] #1535: numpy.random.permutations fails for non-integer arguments

NumPy Trac numpy-tickets@scipy....
Tue Jul 6 02:23:09 CDT 2010


#1535: numpy.random.permutations fails for non-integer arguments
------------------------------------+---------------------------------------
 Reporter:  robince                 |       Owner:  somebody
     Type:  defect                  |      Status:  new     
 Priority:  normal                  |   Milestone:  2.0.0   
Component:  numpy.random            |     Version:          
 Keywords:  permutation long 64bit  |  
------------------------------------+---------------------------------------

Comment(by cgohlke):

 How about this?

 {{{
 Index: mtrand.pyx
 ===================================================================
 --- mtrand.pyx  (revision 8469)
 +++ mtrand.pyx  (working copy)
 @@ -4226,10 +4226,10 @@
          array([15,  1,  9,  4, 12])

          """
 -        if isinstance(x, (int, np.integer)):
 +        if hasattr(x, '__iter__'):
 +            arr = np.array(x)
 +        else:
              arr = np.arange(x)
 -        else:
 -            arr = np.array(x)
          self.shuffle(arr)
          return arr
 }}}


 {{{
 >>> x = np.array([1,2,3], dtype=float)
 >>> np.random.permutation(x[1])
 array([ 0.,  1.])
 >>> type(x.shape[0])
 <type 'long'>
 >>> np.random.permutation(x.shape[0])
 array([0, 2, 1], dtype=int64)
 }}}


 {{{
 >>> x = 10000000000000000000
 >>> type(x)
 <type 'long'>
 >>> np.random.permutation(x)
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "mtrand.pyx", line 4232, in mtrand.RandomState.permutation
   (build\scons\numpy\random\mtrand\mtrand.c:18840)
 ValueError: Maximum allowed size exceeded
 }}}

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1535#comment:2>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list