When using the random
library in Python, I can do the following just fine
>>> import random
>>> random.seed("twenty five")
but if i'm using NumPy to generate random numbers, I cannot set the seed with a string
>>> import numpy as np
>>> np.random.seed("twenty five")
Traceback (most recent call last):
File "_mt19937.pyx", line 178, in numpy.random._mt19937.MT19937._legacy_seeding
TypeError: 'str' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mtrand.pyx", line 244, in numpy.random.mtrand.RandomState.seed
File "_mt19937.pyx", line 166, in numpy.random._mt19937.MT19937._legacy_seeding
File "_mt19937.pyx", line 186, in numpy.random._mt19937.MT19937._legacy_seeding
TypeError: Cannot cast scalar from dtype('<U11') to dtype('int64') according to the rule 'safe'
Is it possible for NumPy to accept string as seed ?
And if not, is there a correct way to transform the string into an int for setting the seed in NumPy ?
What is the mechanism behind the seed
function of the random
library that makes it able to accept string seeds ?
Aucun commentaire:
Enregistrer un commentaire