You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/09/17 06:07:17 UTC

[GitHub] [incubator-mxnet] reminisce commented on a change in pull request #15909: [numpy] random.rand

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

 ##########
 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:
   `uniform` samples over the range `[0, 1]`, while `rand` samples over the range `[0, 1)`. To simulate this behavior using `uniform`, the upper bound should be set to `1 - np.finfo(dtype).eps`.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services