美文网首页Tensorflow
TensorFlow学习笔记(17)random_ops.ran

TensorFlow学习笔记(17)random_ops.ran

作者: 谢昆明 | 来源:发表于2018-11-20 23:17 被阅读0次

均匀分布随机数

函数名有两种写法
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())

相关文章

网友评论

    本文标题:TensorFlow学习笔记(17)random_ops.ran

    本文链接:https://www.haomeiwen.com/subject/twpfqqtx.html