I’m trying to match randomly generated ndarrays from numpy with MATLAB.
import numpy as np
# Set the seed for NumPy's random generator
np.random.seed(42) #Mersenne Twister is default
# Generate complex random numbers
a = 16
b = 4
c = 10
x_py = np.random.rand(a, b, c) + 1j * np.random.rand(a, b, c)
Here’s the MATLAB version:
% Set the seed for MATLAB's random generator
rng(42, 'twister') % Use the Mersenne Twister algorithm
% Generate complex random numbers
a = 16;
b = 4;
c = 10;
x_ml = rand([a, b, c], 'like', 1i);
Now, although the seed and generator type are matched, the states don’t match, so I wasn’t able to match x_py and x_ml.
I know the easier way is to generate in MATLAB, save to file and import in Python, but I want to understand the difference between the way the two APIs work and how they can be tweaked to get a matching output.