I am trying to compare my functions in vanilla Python/Numpy to those of PyTorch. For that I would like to set the seed of both to make the results comparable.
Is it possible to set the seed for numpy like np.random.seed(x) and PyTorch like torch.manual_seed(x) so that both produce the same random numbers?
Right now, with the same x value np.random.uniform(0, 1) and torch.rand(1) produce different outputs.
What do you think of this solution?
Instead of
np.random.seed(0)
np.random.rand(0, 1)
you could use
torch.manual_seed(0)
torch.rand(1).numpy()
That way, you will have the same random numbers between PyTorch and NumPy, but still as a NumPy array if you want...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With