Parameters:
————————————————————————————————————
Seed: if seed is none, random state singleton (NP. Random) is returned
If seed is int, a new random state instance is returned, which is generated by the new seed
If seed is a random state instance, it returns itself directly
Process
————————————————————————————————————
defcheck_random_state(seed):
"""Turnseedintoanp.random.RandomStateinstance
IfseedisNone,returntheRandomStatesingletonusedbynp.random.
Ifseedisanint,returnanewRandomStateinstanceseededwithseed.
IfseedisalreadyaRandomStateinstance,returnit.
OtherwiseraiseValueError.
"""
#Returns np.random.mtrand._rand if seed is None or np.random.
ifseedisNoneorseedisnp.random:
returnnp.random.mtrand._rand
#seed for numbers.Intergral or np.integer instances.
ifisinstance(seed,(numbers.Integral,np.integer)):
returnnp.random.RandomState(seed)
#Returns itself if it is np.random.RandomState.
ifisinstance(seed,np.random.RandomState):
returnseed
# Error is reported if it is not the above case.
raiseValueError('%rcannotbeusedtoseedanumpy.random.RandomState'
'instance'%seed)
Similar Posts:
- [Solved] Pycharm Error: Error: failed to send plot to http://127.0.0.1:63342
- [Solved] Importerror: DLL load failed while importing mtrand: the specified program could not be found.
- Day 1 – meet Tornado
- How to Solve Rac ORA-01102 error: cannot mount database in EXCLUSIVE mode
- ERROR: syntax error at end of input & Database Error: invalid input syntax for type numeric: “Not reviewed”
- [Solved] Redis has java.net.socketexception: permission denied: connect problem during stress test
- Fragment not attached to Activity [How to Solve]
- [Solved] Java collections.sort Error: Comparison method violates its general contract!
- Python3 urlopen() TypeError: can’t convert ‘bytes’ object to str im…
- Problems of java.sql.sqlrecoveryexception: IO error: connection reset of ojdbc in Linux Environment