从均匀分布中输出确定性伪随机值。
用法
tf.random.stateless_uniform(
shape, seed, minval=0, maxval=None, dtype=tf.dtypes.float32, name=None,
alg='auto_select'
)参数
-
shape一维整数张量或 Python 数组。输出张量的形状。 -
seed形状 [2] 张量,随机数生成器的种子。必须具有数据类型int32或int64。 (使用 XLA 时,仅允许使用int32。) -
minvaldtype类型的张量或 Python 值,可使用shape广播(对于整数类型,不支持广播,因此它需要是标量)。要生成的随机值范围的下限。将None传递给 full-range 整数。默认为 0。 -
maxvaldtype类型的张量或 Python 值,可使用shape广播(对于整数类型,不支持广播,因此它需要是标量)。要生成的随机值范围的上限。如果dtype是浮点数,则默认为 1。将None传递给 full-range 整数。 -
dtype输出的类型:float16,bfloat16,float32,float64,int32或int64。对于无界统一整数(minval,maxval和None),可以使用uint32和uint64。默认为float32。 -
name操作的名称(可选)。 -
alg用于生成随机数的 RNG 算法。有效的选择是"philox"为了Philox 算法,"threefry"为了ThreeFry 算法, 和"auto_select"(默认)系统根据设备类型自动选择算法。的值tf.random.Algorithm也可以使用。请注意,与"auto_select",此函数的输出在不同设备上运行时可能会发生变化。
返回
- 用随机统一值填充的指定形状的张量。
抛出
-
ValueError如果dtype是整数并且仅指定了minval或maxval之一。
这是tf.random.uniform 的无状态版本:如果使用相同的种子和形状运行两次,它将产生相同的伪随机数。输出在同一硬件(以及 CPU 和 GPU 之间)上的多次运行中是一致的,但可能会在 TensorFlow 版本之间或在非 CPU/GPU 硬件上发生变化。
生成的值遵循 [minval, maxval) 范围内的均匀分布。下限 minval 包含在范围内,而上限 maxval 不包括在内。
对于浮点数,默认范围是 [0, 1) 。对于整数,至少必须明确指定maxval。
在整数情况下,随机整数略有偏差,除非 maxval - minval 是 2 的精确幂。对于明显小于输出范围(2**32 或 2**64)的 maxval - minval 的值,偏差很小。
对于 full-range(即包括最大值和最小值)随机整数,将 minval=None 和 maxval=None 与整数 dtype 一起传递。对于整数 dtype,minval 和 maxval 都必须是 None 或者两者都不能是 None 。例如:
ints = tf.random.stateless_uniform(
[10], seed=(2, 3), minval=None, maxval=None, dtype=tf.int32)
相关用法
- Python tf.random.stateless_parameterized_truncated_normal用法及代码示例
- Python tf.random.stateless_poisson用法及代码示例
- Python tf.random.stateless_binomial用法及代码示例
- Python tf.random.stateless_categorical用法及代码示例
- Python tf.random.stateless_gamma用法及代码示例
- Python tf.random.shuffle用法及代码示例
- Python tf.random.set_global_generator用法及代码示例
- Python tf.random.set_seed用法及代码示例
- Python tf.random.truncated_normal用法及代码示例
- Python tf.random.Generator用法及代码示例
- Python tf.random.Generator.binomial用法及代码示例
- Python tf.random.normal用法及代码示例
- Python tf.random.experimental.stateless_split用法及代码示例
- Python tf.random.uniform用法及代码示例
- Python tf.random.categorical用法及代码示例
- Python tf.random.experimental.stateless_fold_in用法及代码示例
- Python tf.random.Generator.make_seeds用法及代码示例
- Python tf.random.poisson用法及代码示例
- Python tf.random.gamma用法及代码示例
- Python tf.random.create_rng_state用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.random.stateless_uniform。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
