numpy.random.randn() function with example in python | 2019

Spread the love

numpy.random.randn() function: This function return a sample (or samples) from the “standard normal” distribution.

If positive, int_like or int-convertible arguments are provided, randn generates an array of shape (d0, d1, …, dn), filled with random floats sampled from a univariate “normal” (Gaussian) distribution of mean 0 and variance 1 (if any of the d_i are floats, they are first converted to integers by truncation). A single float randomly sampled from the distribution is returned if no argument is provided.

This is a convenience function. If you want an interface that takes a tuple as the first argument, use numpy.random.standard_normal instead.

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.

Z : ndarray or float
A (d0, d1, …, dn)-shaped array of floating-point samples from the standard normal distribution, or a single such float if no parameters were supplied.

#example program on numpy.random.randn() function

import numpy as np print(np.random.randn()) print(np.random.randn(2,3))


[[-0.64863636 -0.28730311 -0.56747547]
 [ 0.9427455  -0.88447682  0.2324423 ]]





Leave a Reply

Your email address will not be published. Required fields are marked *