python - Comparing Matlab and Numpy code that uses random number generation -
is there way make random number generator in numpy generate same random numbers in matlab, given same seed?
i tried following in matlab:
>> rng(1); >> randn(2, 2) ans = 0.9794 -0.5484 -0.2656 -0.0963
and following in ipython numpy:
in [21]: import numpy np in [22]: np.random.seed(1) in [23]: np.random.randn(2, 2) out[23]: array([[ 1.624, -0.612], [-0.528, -1.073]])
values in both arrays different.
or suggest idea compare 2 implementations of same algorithm in matlab , python uses random number generation.
thanks!
one way ensure same numbers fed process generate them in 1 of 2 languges, save them , import other language. easy, write them in simple textfile.
if not possible or desirable, can make sure numbers same doing generation of pseudo random numbers yourself. here site shows simple example of easy implement algorithm: build own simple random numbers
if quality of homemade random generator not sufficient, can build random generation function in 1 language, , call other. easiest path call matlab python.
if feeling lucky, try playing around settings. example try using (outdated)
seed
input matlabs random functions. or try using different kinds of generators. believe default in both languages mersenne twister, if implementation not same, perhaps simpler 1 is.
Comments
Post a Comment