[Numpy-tickets] [NumPy] #427: numpy.random.permutation cannot handle numpy integer scalars

NumPy numpy-tickets at scipy.net
Thu Jan 18 11:34:20 CST 2007


#427: numpy.random.permutation cannot handle numpy integer scalars
--------------------------+-------------------------------------------------
 Reporter:  rkern         |       Owner:  rkern        
     Type:  defect        |      Status:  new          
 Priority:  normal        |   Milestone:  1.0.2 Release
Component:  numpy.random  |     Version:  devel        
 Severity:  normal        |    Keywords:               
--------------------------+-------------------------------------------------
 As reported by Emanuele Olivetti:

 {{{

 Look at this:

 ----------bug.py-------
 import numpy
 a=numpy.array([1,2])
 b=a.sum()
 print type(b)
 c=numpy.random.permutation(b)
 -----------------------

 If I run it (Python 2.5, numpy 1.0.1 on a Linux box) I get:
 -----------
 #> python /tmp/bug.py
 <type 'numpy.int32'>
 Traceback (most recent call last):
   File "/tmp/bug.py", line 5, in <module>
     c=numpy.random.permutation(b)
   File "mtrand.pyx", line 1227, in mtrand.RandomState.permutation
   File "mtrand.pyx", line 1211, in mtrand.RandomState.shuffle
 TypeError: len() of unsized object
 -----------
 }}}

 We are currently using {{{type(x) is int}}} to distinguish integers from
 arrays. We should test for {{{isinstance(x, int) or
 isinstance(numpy.integer)}}}, I believe. Possibly, we should also check
 for {{{hasattr(x, '__index__')}}}.

-- 
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/427>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list