On 10/26/11 2:41 PM, Jose Guzman wrote:
Hi everybody,
When trying to set a seed in Sage:
sage: import numpy as np
sage: np.random.seed(10)
I've got the following error:
sage: np.random.seed(10)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
$HOME/programming/Sage/tests/<ipython console> in <module>()
$HOME/sage-4.7/local/lib/python2.6/site-packages/numpy/random/mtrand.so
in mtrand.RandomState.seed (numpy/random/mtrand/mtrand.c:4842)()
ValueError: object of too small depth for desired array
However, if I do:
sage: import numpy as np
sage: np.random.seed(int(10))
everything works nicely.
Not sure if we should set a seed in a different way in Sage (I am
running Sage 4.7.1). I wonder if is there any easy way to solve this
small bug (I would be happy to submit a patch).
Most likely, the problem here is that numpy doesn't recognize Sage
Integer objects as being convertable to python integers. I think this
is a failing of numpy (it should check the __index__ method to see if it
can convert the Integer to a python integer).
This will solve the original problem:
np.random.seed(10r)
(10r tells the Sage preparser to not make 10 a Sage Integer object, but
instead, make it a python "raw" integer).
Jason
--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org