dask 2021.10.0

NotesParametersReturns
lognormal(self, mean=0.0, sigma=1.0, size=None, chunks='auto', **kwargs)

This docstring was copied from numpy.random.mtrand.RandomState.lognormal.

Some inconsistencies with the Dask version may exist.

Draw samples from a log-normal distribution with specified mean, standard deviation, and array shape. Note that the mean and standard deviation are not the values for the distribution itself, but of the underlying normal distribution it is derived from.

note

New code should use the lognormal method of a default_rng() instance instead; please see the :None:ref:`random-quick-start`.

Notes

A variable :None:None:`x` has a log-normal distribution if :None:None:`log(x)` is normally distributed. The probability density function for the log-normal distribution is:

$$p(x) = \frac{1}{\sigma x \sqrt{2\pi}}e^{(-\frac{(ln(x)-\mu)^2}{2\sigma^2})}$$

where $\mu$ is the mean and $\sigma$ is the standard deviation of the normally distributed logarithm of the variable. A log-normal distribution results if a random variable is the product of a large number of independent, identically-distributed variables in the same way that a normal distribution results if the variable is the sum of a large number of independent, identically-distributed variables.

Parameters

mean : float or array_like of floats, optional

Mean value of the underlying normal distribution. Default is 0.

sigma : float or array_like of floats, optional

Standard deviation of the underlying normal distribution. Must be non-negative. Default is 1.

size : int or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k) , then m * n * k samples are drawn. If size is None (default), a single value is returned if mean and sigma are both scalars. Otherwise, np.broadcast(mean, sigma).size samples are drawn.

Returns

out : ndarray or scalar

Drawn samples from the parameterized log-normal distribution.

Draw samples from a log-normal distribution.

See Also

Generator.lognormal

which should be used for new code.

scipy.stats.lognorm

probability density function, distribution, cumulative density function, etc.

Examples

Draw samples from the distribution:

This example is valid syntax, but we were not able to check execution
>>> mu, sigma = 3., 1. # mean and standard deviation  # doctest: +SKIP
... s = np.random.lognormal(mu, sigma, 1000) # doctest: +SKIP

Display the histogram of the samples, along with the probability density function:

This example is valid syntax, but we were not able to check execution
>>> import matplotlib.pyplot as plt  # doctest: +SKIP
... count, bins, ignored = plt.hist(s, 100, density=True, align='mid') # doctest: +SKIP
This example is valid syntax, but we were not able to check execution
>>> x = np.linspace(min(bins), max(bins), 10000)  # doctest: +SKIP
... pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)) # doctest: +SKIP
...  / (x * sigma * np.sqrt(2 * np.pi)))
This example is valid syntax, but we were not able to check execution
>>> plt.plot(x, pdf, linewidth=2, color='r')  # doctest: +SKIP
... plt.axis('tight') # doctest: +SKIP
... plt.show() # doctest: +SKIP

Demonstrate that taking the products of random samples from a uniform distribution can be fit well by a log-normal probability density function.

This example is valid syntax, but we were not able to check execution
>>> # Generate a thousand samples: each is the product of 100 random
... # values, drawn from a normal distribution.
... b = [] # doctest: +SKIP
... for i in range(1000): # doctest: +SKIP
...  a = 10. + np.random.standard_normal(100)
...  b.append(np.product(a))
This example is valid syntax, but we were not able to check execution
>>> b = np.array(b) / np.min(b) # scale values to be positive  # doctest: +SKIP
... count, bins, ignored = plt.hist(b, 100, density=True, align='mid') # doctest: +SKIP
... sigma = np.std(np.log(b)) # doctest: +SKIP
... mu = np.mean(np.log(b)) # doctest: +SKIP
This example is valid syntax, but we were not able to check execution
>>> x = np.linspace(min(bins), max(bins), 10000)  # doctest: +SKIP
... pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)) # doctest: +SKIP
...  / (x * sigma * np.sqrt(2 * np.pi)))
This example is valid syntax, but we were not able to check execution
>>> plt.plot(x, pdf, color='r', linewidth=2)  # doctest: +SKIP
... plt.show() # doctest: +SKIP
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /dask/array/random.py#315
type: <class 'function'>
Commit: