從均勻分布中輸出確定性偽隨機值。
用法
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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
