xidulu commented on a change in pull request #15909: [numpy] random.rand
URL: https://github.com/apache/incubator-mxnet/pull/15909#discussion_r325076641
 
 

 ##########
 File path: python/mxnet/numpy/random.py
 ##########
 @@ -20,7 +20,34 @@
 from __future__ import absolute_import
 from ..ndarray import numpy as _mx_nd_np
 
-__all__ = ['uniform', 'normal']
+__all__ = ['uniform', 'normal', 'rand']
+
+
+def rand(*size, **kwargs):
+    r"""Random values in a given shape.
+
+    Create an array of the given shape and populate it with random
+    samples from a uniform distribution over [0, 1).
+    Parameters
+    ----------
+    d0, d1, ..., dn : int, optional
+        The dimensions of the returned array, should be all positive.
+        If no argument is given a single Python float is returned.
+    Returns
+    -------
+    out : ndarray
+       Random values.
+    Examples
+    --------
+    >>> np.random.rand(3,2)
+    array([[ 0.14022471,  0.96360618],  #random
+           [ 0.37601032,  0.25528411],  #random
+           [ 0.49313049,  0.94909878]]) #random
+    """
+    output_shape = ()
+    for s in size:
+        output_shape += (s,)
+    return _mx_nd_np.random.uniform(0, 1, size=output_shape, **kwargs)
 
 Review comment:
   @reminisce 
   I believe `mx.np.uniform` actually samples from `[0, 1)`, as the latest 
implementation is based on `mshadow/random.h` 
(https://github.com/apache/incubator-mxnet/blob/1434b98e26ace5300f17465fbb2942272a3dfd77/3rdparty/mshadow/mshadow/random.h#L118),
 which, according to the comment, generates uniform distributed numbers in 
range `[a, b)`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to