ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 23 Jan 2012 13:29:26 +0100Bug in initializing randomhttps://ask.sagemath.org/question/7567/bug-in-initializing-random/Or maybe a feature? In normal python + numpy
import numpy.random as random
random.RandomState(22)
works as expected, whereas in sage, the input has to be an array (e.g. [22]). Anyone know why? Mon, 23 Jan 2012 12:09:55 +0100https://ask.sagemath.org/question/7567/bug-in-initializing-random/Answer by Jason Grout for <p>Or maybe a feature? In normal python + numpy</p>
<p>import numpy.random as random
random.RandomState(22)</p>
<p>works as expected, whereas in sage, the input has to be an array (e.g. [22]). Anyone know why? </p>
https://ask.sagemath.org/question/7567/bug-in-initializing-random/?answer=13180#post-id-13180This is because numpy does not recognize Sage integers as scalars. This is arguably a bug in numpy (since it is checking for scalars by looking at the type, rather than trying to coerce to an integer using the standard python functions to do so). A workaround is to use int(22) or 22r (i.e., a 'raw' 22) instead.Mon, 23 Jan 2012 13:29:26 +0100https://ask.sagemath.org/question/7567/bug-in-initializing-random/?answer=13180#post-id-13180