TensorFlow学习笔记(17)random_ops.random_uniform浅析

均匀分布随机数

函数名有两种写法
tf.random.uniform
tf.random_uniform

tf.random.uniform(
    shape,
    minval=0,
    maxval=None,
    dtype=tf.float32,
    seed=None,
    name=None
)

The generated values follow a uniform distribution in the range [minval, maxval). The lower bound minval is included in the range, while the upper bound maxval is excluded.
For floats, the default range is [0, 1). For ints, at least maxval must be specified explicitly.
生成均为分布的随机值,取值范围为[minval, maxval)
floats的默认取值范围为[0,1), ints需要指定最大值

测试代码

    random = random_ops.random_uniform(
                    noise_shape, seed=None, dtype=x.dtype)
    #  [0.23802626 0.12538171 0.36279774 0.9606353  0.28212202 0.52161884
    #   0.15747523 0.42480624 0.8671547  0.77771187]
    print(random.eval())
    原文作者:谢昆明
    原文地址: https://www.jianshu.com/p/55b265e26e47
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞