TensorFlow+Numpy笔记(持续更新)

目录

参考:
TensorFlow关于PythonAPI的官方档案
NumPy官方档案

NumPy

Random sampling

Random generator

numpy.random.RandomState(seed= None)
官方档案
基于梅森旋转算法,产生伪随机数。梅森旋转算法是一个随机性相当强的算法,其周期可以达到\(2^{19937}-1\),几乎不会出现重复。

seed可以是介于0和\(2^{32}-1\)之间的任意一个整数,或是由这些整数构成的一个tuple。
如果是None,RandomState will try to read data from /dev/urandom (or the Windows analogue) if available or seed from the clock otherwise.

A fixed seed and a fixed series of calls to ‘RandomState’ methods using the same parameters will always produce the same results up to roundoff error.
这所谓的calls需要通过随机函数实现,来调用该伪随机数发生器。Methods见官方档案最下面长长的列表。

import numpy

for i in [1,2,3]:
    rng = numpy.random.RandomState(23455)
    arrayA = rng.uniform(0,1,(2,3))
    print(arrayA)
# 结果一样:
[[0.83494319 0.11482951 0.66899751]
 [0.46594987 0.60181666 0.58838408]]
[[0.83494319 0.11482951 0.66899751]
 [0.46594987 0.60181666 0.58838408]]
[[0.83494319 0.11482951 0.66899751]
 [0.46594987 0.60181666 0.58838408]]

猜你喜欢

转载自www.cnblogs.com/RyanXing/p/9464372.html