Table Of Contents
Table Of Contents


mxnet.ndarray.random.uniform(low=0, high=1, shape=_Null, dtype=_Null, ctx=None, out=None, **kwargs)[source]

Draw random samples from a uniform distribution.

Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high).

  • low (float or NDArray, optional) – Lower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.

  • high (float or NDArray, optional) – Upper boundary of the output interval. All values generated will be less than high. The default value is 1.0.

  • shape (int or tuple of ints, optional) – The number of samples to draw. If shape is, e.g., (m, n) and low and high are scalars, output shape will be (m, n). If low and high are NDArrays with shape, e.g., (x, y), then output will have shape (x, y, m, n), where m*n samples are drawn for each [low, high) pair.

  • dtype ({'float16', 'float32', 'float64'}, optional) – Data type of output samples. Default is ‘float32’

  • ctx (Context, optional) – Device context of output. Default is current context. Overridden by low.context when low is an NDArray.

  • out (NDArray, optional) – Store output to an existing NDArray.


>>> mx.nd.random.uniform(0, 1)
[ 0.54881352]
<NDArray 1 @cpu(0)
>>> mx.nd.random.uniform(0, 1, ctx=mx.gpu(0))
[ 0.92514056]
<NDArray 1 @gpu(0)>
>>> mx.nd.random.uniform(-1, 1, shape=(2,))
[ 0.71589124  0.08976638]
<NDArray 2 @cpu(0)>
>>> low = mx.nd.array([1,2,3])
>>> high = mx.nd.array([2,3,4])
>>> mx.nd.random.uniform(low, high, shape=2)
[[ 1.78653979  1.93707538]
 [ 2.01311183  2.37081361]
 [ 3.30491424  3.69977832]]
<NDArray 3x2 @cpu(0)>