numpy.random.RandomState()用法

个人笔记使用,转自@william_hehe , 侵删,看了几篇感觉这个最简单明了易理解。
RandomState():随机数种子
功能:随机产生所需数据。

import numpy
for i in [1,2,3,4]:
#    当参数为None时,生成的数据为随机数据。
    a=numpy.random.RandomState(None)
    b=a.rand(1,2)
    print(i)
    print(b)

结果:
1
[[ 0.63678388 0.53997544]]
2
[[ 0.88420701 0.11569489]]
3
[[ 0.55099434 0.9790908 ]]
4
[[ 0.6769419 0.42401973]]

—————————————————————

import numpy
for i in [1,2,3,4]:
#    当参数为常数时,生成的数据为恒定数据。
    a=numpy.random.RandomState(1)
    b=a.rand(1,2)
    print(i)
    print(b)

结果:
1
[[ 0.417022 0.72032449]]
2
[[ 0.417022 0.72032449]]
3
[[ 0.417022 0.72032449]]
4
[[ 0.417022 0.72032449]]

猜你喜欢

转载自blog.csdn.net/kudou1994/article/details/81287156