tf.random.uniform
Stay organized with collections
Save and categorize content based on your preferences.
Outputs random values from a uniform distribution.
tf.random.uniform(
shape, minval=0, maxval=None, dtype=tf.dtypes.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.
In the integer case, the random integers are slightly biased unless
maxval - minval
is an exact power of two. The bias is small for values of
maxval - minval
significantly smaller than the range of the output (either
2**32
or 2**64
).
Args |
shape
|
A 1-D integer Tensor or Python array. The shape of the output tensor.
|
minval
|
A 0-D Tensor or Python value of type dtype . The lower bound on the
range of random values to generate. Defaults to 0.
|
maxval
|
A 0-D Tensor or Python value of type dtype . The upper bound on
the range of random values to generate. Defaults to 1 if dtype is
floating point.
|
dtype
|
The type of the output: float16 , float32 , float64 , int32 ,
or int64 .
|
seed
|
A Python integer. Used to create a random seed for the distribution.
See tf.compat.v1.set_random_seed
for behavior.
|
name
|
A name for the operation (optional).
|
Returns |
A tensor of the specified shape filled with random uniform values.
|
Raises |
ValueError
|
If dtype is integral and maxval is not specified.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.random.uniform\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/random/uniform) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/ops/random_ops.py#L186-L252) |\n\nOutputs random values from a uniform distribution.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.random.uniform`](/api_docs/python/tf/random/uniform), [`tf.compat.v1.random_uniform`](/api_docs/python/tf/random/uniform)\n\n\u003cbr /\u003e\n\n tf.random.uniform(\n shape, minval=0, maxval=None, dtype=tf.dtypes.float32, seed=None, name=None\n )\n\nThe generated values follow a uniform distribution in the range\n`[minval, maxval)`. The lower bound `minval` is included in the range, while\nthe upper bound `maxval` is excluded.\n\nFor floats, the default range is `[0, 1)`. For ints, at least `maxval` must\nbe specified explicitly.\n\nIn the integer case, the random integers are slightly biased unless\n`maxval - minval` is an exact power of two. The bias is small for values of\n`maxval - minval` significantly smaller than the range of the output (either\n`2**32` or `2**64`).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `shape` | A 1-D integer Tensor or Python array. The shape of the output tensor. |\n| `minval` | A 0-D Tensor or Python value of type `dtype`. The lower bound on the range of random values to generate. Defaults to 0. |\n| `maxval` | A 0-D Tensor or Python value of type `dtype`. The upper bound on the range of random values to generate. Defaults to 1 if `dtype` is floating point. |\n| `dtype` | The type of the output: `float16`, `float32`, `float64`, `int32`, or `int64`. |\n| `seed` | A Python integer. Used to create a random seed for the distribution. See [`tf.compat.v1.set_random_seed`](../../tf/compat/v1/set_random_seed) for behavior. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A tensor of the specified shape filled with random uniform values. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-------------------------------------------------------|\n| `ValueError` | If `dtype` is integral and `maxval` is not specified. |\n\n\u003cbr /\u003e"]]