Improve the document of rand/randn with examples
@@ -14,7 +14,7 @@ def rand(*size, **kwarg):
distributed (i.i.d.).
Args:
- size (tuple of ints): The shape of the array.
+ size (ints): The shape of the array.
dtype: Data type specifier. Only :class:`numpy.float32` and
:class:`numpy.float64` types are allowed. The default is
:class:`numpy.float64`.
@@ -24,6 +24,18 @@ def rand(*size, **kwarg):
.. seealso:: :func:`numpy.random.rand`
+ .. admonition:: Example
+
+ >>> cupy.random.rand(3, 2)
+ array([[0.86476479, 0.05633727], # random
+ [0.27283185, 0.38255354], # random
+ [0.16592278, 0.75150313]]) # random
+
+ >>> cupy.random.rand(3, 2, dtype=cupy.float32)
+ array([[0.9672306 , 0.9590486 ], # random
+ [0.6851264 , 0.70457625], # random
+ [0.22382522, 0.36055237]], dtype=float32) # random
+
"""
dtype = kwarg.pop('dtype', float)
if kwarg:
@@ -40,7 +52,7 @@ def randn(*size, **kwarg):
(i.i.d.).
Args:
- size (tuple of ints): The shape of the array.
+ size (ints): The shape of the array.
dtype: Data type specifier. Only :class:`numpy.float32` and
:class:`numpy.float64` types are allowed.
The default is :class:`numpy.float64`.
@@ -50,6 +62,18 @@ def randn(*size, **kwarg):
.. seealso:: :func:`numpy.random.randn`
+ .. admonition:: Example
+
+ >>> cupy.random.randn(3, 2)
+ array([[0.41193321, 1.59579542], # random
+ [0.47904589, 0.18566376], # random
+ [0.59748424, 2.32602829]]) # random
+
+ >>> cupy.random.randn(3, 2, dtype=cupy.float32)
+ array([[ 0.1373886 , 2.403238 ], # random
+ [ 0.84020025, 1.5089266 ], # random
+ [-1.2268474 , -0.48219103]], dtype=float32) # random
+
"""
dtype = kwarg.pop('dtype', float)
if kwarg:
