2

When I do the following in Python:

>>> import numpy
>>> numpy.random.RandomState()

it returns RandomState(MT19937) at 0x2BABD069FBA0. I understand the first part of the output, but I fail to understand the meaning of the hexadecimal part. It doesn't seem to be the random seed as well. I tried to check online but couldn't find any information on this. Please may I ask if anyone understands the meaning of the hexadecimal number? Many thanks!

Hadi Mir
  • 4,497
  • 2
  • 29
  • 31
ababovb
  • 23
  • 6

3 Answers3

2

I think it is the memory address pointing to where the object was instanced

>>> x = np.random.RandomState()
>>> x
RandomState(MT19937) at 0x2D5545AAE40
>>> print(hex(id(x)))
0x2d5545aae40
Melo
  • 113
  • 8
1

The hex part is just the memory address. checkout this link to get more idea.

Hadi Mir
  • 4,497
  • 2
  • 29
  • 31
1

As others have mentioned, that's the address of the object. I assume you are interested in a form of representation of the state that can be saved and possibly restored at a later time. If that's the case you can use get_state() in the following way:

In [1]: import numpy
In [2]: rs = numpy.random.RandomState()
In [3]: state = rs.get_state()
In [4]: rs.rand()
Out[4]: 0.432259232330229
In [5]: rs.rand()
Out[5]: 0.8136168709684055
In [6]: rs.set_state(state)
In [7]: rs.rand()
Out[7]: 0.432259232330229
In [8]: rs.rand()
Out[8]: 0.8136168709684055
In [9]: state
Out[9]: 
('MT19937',
 array([2147483648, 3210667685, 2075287668, 1343092412,  968114203,
        2132083310, 3622729752, 1799367345, 3280163148, 1700822427,
[...]
        1081150080, 3649194061, 1333345922,  800258004, 1698645582,
        3374395214, 2706341428,  849808433,  570983609], dtype=uint32),
 623,
 0,
 0.0)

The last line shows "the random seed".

Luca Citi
  • 1,310
  • 9
  • 9