bundles / numpy 2.4.3 / numpy / random / RandomState / laplace
cython_function_or_method
numpy.random:RandomState.laplace
Signature
def laplace ( loc = 0.0 , scale = 1.0 , size = None ) Summary
Draw samples from the Laplace or double exponential distribution with specified location (or mean) and scale (decay).
Extended Summary
The Laplace distribution is similar to the Gaussian/normal distribution, but is sharper at the peak and has fatter tails. It represents the difference between two independent, identically distributed exponential random variables.
Parameters
loc: float or array_like of floats, optionalThe position, , of the distribution peak. Default is 0.
scale: float or array_like of floats, optional, the exponential decay. Default is 1. Must be non- negative.
size: int or tuple of ints, optionalOutput shape. If the given shape is, e.g.,
(m, n, k), thenm * n * ksamples are drawn. If size isNone(default), a single value is returned iflocandscaleare both scalars. Otherwise,np.broadcast(loc, scale).sizesamples are drawn.
Returns
out: ndarray or scalarDrawn samples from the parameterized Laplace distribution.
Notes
It has the probability density function
The first law of Laplace, from 1774, states that the frequency of an error can be expressed as an exponential function of the absolute magnitude of the error, which leads to the Laplace distribution. For many problems in economics and health sciences, this distribution seems to model the data better than the standard Gaussian distribution.
Examples
Draw samples from the distributionloc, scale = 0., 1. s = np.random.laplace(loc, scale, 1000)✓
import matplotlib.pyplot as plt count, bins, ignored = plt.hist(s, 30, density=True) x = np.arange(-8., 8., .01) pdf = np.exp(-abs(x-loc)/scale)/(2.*scale)✓
plt.plot(x, pdf)
✗g = (1/(scale * np.sqrt(2 * np.pi)) * np.exp(-(x - loc)**2 / (2 * scale**2)))✓
plt.plot(x,g)
✗See also
- random.Generator.laplace
which should be used for new code.
Aliases
-
numpy.random.laplace -
numpy.random.RandomState.laplace