以下是两行代码,用于生成大小为4的随机置换:
from numpy import random
t = random.permutation(4)
这可以在Python中执行,但不可以在Sage中执行,会出现以下错误:
TypeError Traceback (most recent call last)
<ipython-input-3-033ef4665637> in <module>()
1 from numpy import random
----> 2 t = random.permutation(Integer(4))
mtrand.pyx in mtrand.RandomState.permutation (numpy/random/mtrand/mtrand.c:34842)()
mtrand.pyx in mtrand.RandomState.shuffle (numpy/random/mtrand/mtrand.c:33796)()
TypeError: len() of unsized object
为什么?
稍微详细一些:我在Python 3中执行了代码,并且 mtrand
也在Python 3目录中,这应该排除了sage调用numpy的Python 2版本的可能性。