Atharva
Atharva

Reputation: 181

Ensure same seed generates same random numbers when using numpy and cupy

I import numpy or cupy as follows:

import numpy as np
# import cupy as np

Then I generate X as follows:

np.random.seed(0)
X = np.random.rand(4, 3)

I get two very different matrices depending on whether np is numpy or cupy.

numpy matrix:

[[0.5488135  0.71518937 0.60276338]
 [0.54488318 0.4236548  0.64589411]
 [0.43758721 0.891773   0.96366276]
 [0.38344152 0.79172504 0.52889492]]

cupy matrix:

[[0.43845084 0.4603647  0.25021471]
 [0.49474377 0.05301112 0.33769926]
 [0.39676252 0.87441866 0.48216683]
 [0.0428398  0.50841419 0.6545497 ]]

How can I generate the same random matrix using both numpy and cupy?

Upvotes: 1

Views: 73

Answers (0)

Related Questions