[NumPy-Tickets] [NumPy] #1535: numpy.random.permutations fails for non-integer arguments
NumPy Trac
numpy-tickets@scipy....
Mon Jul 5 09:46:47 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 |
------------------------------------+---------------------------------------
Changes (by vincentdavis):
* cc: vincent@… (added)
Comment:
np.random.permutation(num) It appears that num needs to be an integer (not
converted from float), in the case of the X.shape[0]
I think this is because numpy does not have a dtype "long" rather it is an
object.
Also if type(num)='Long' than np.random.permutation(num) fails
{{{
>>> 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 4233, in mtrand.RandomState.permutation
(build/scons/numpy/random/mtrand/mtrand.c:18875)
File "mtrand.pyx", line 4176, in mtrand.RandomState.shuffle
(build/scons/numpy/random/mtrand/mtrand.c:18466)
TypeError: len() of unsized object
}}}
But these errors are different than just choosing too large int, in that
case the error is
{{{
>>> x = 1000000000000000000
>>> type(x)
<type 'int'>
>>> np.random.permutation(x)
Python(9434) malloc: *** mmap(size=8000000000000000000) failed (error
code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mtrand.pyx", line 4230, in mtrand.RandomState.permutation
(build/scons/numpy/random/mtrand/mtrand.c:18823)
MemoryError
}}}
{{{
>>> x = np.array([1,2,3], dtype=float)
>>> np.random.permutation(x[1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mtrand.pyx", line 4233, in mtrand.RandomState.permutation
(build/scons/numpy/random/mtrand/mtrand.c:18875)
File "mtrand.pyx", line 4176, in mtrand.RandomState.shuffle
(build/scons/numpy/random/mtrand/mtrand.c:18466)
TypeError: len() of unsized object
}}}
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1535#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list