gamma(self, shape, scale=1.0, size=None, chunks='auto', **kwargs)
This docstring was copied from numpy.random.mtrand.RandomState.gamma.
Some inconsistencies with the Dask version may exist.
Samples are drawn from a Gamma distribution with specified parameters, shape
(sometimes designated "k") and :None:None:`scale`
(sometimes designated "theta"), where both parameters are > 0.
New code should use the gamma
method of a default_rng()
instance instead; please see the :None:ref:`random-quick-start`
.
The probability density for the Gamma distribution is
$$p(x) = x^{k-1}\frac{e^{-x/\theta}}{\theta^k\Gamma(k)},$$where $k$ is the shape and $\theta$ the scale, and $\Gamma$ is the Gamma function.
The Gamma distribution is often used to model the times to failure of electronic components, and arises naturally in processes for which the waiting times between Poisson distributed events are relevant.
The shape of the gamma distribution. Must be non-negative.
The scale of the gamma distribution. Must be non-negative. Default is equal to 1.
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 shape
and scale
are both scalars. Otherwise, np.broadcast(shape, scale).size
samples are drawn.
Drawn samples from the parameterized gamma distribution.
Draw samples from a Gamma distribution.
Generator.gamma
which should be used for new code.
scipy.stats.gamma
probability density function, distribution or cumulative density function, etc.
Draw samples from the distribution:
This example is valid syntax, but we were not able to check execution>>> shape, scale = 2., 2. # mean=4, std=2*sqrt(2) # doctest: +SKIP
... s = np.random.gamma(shape, scale, 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: +SKIPSee :
... import scipy.special as sps # doctest: +SKIP
... count, bins, ignored = plt.hist(s, 50, density=True) # doctest: +SKIP
... y = bins**(shape-1)*(np.exp(-bins/scale) / # doctest: +SKIP
... (sps.gamma(shape)*scale**shape))
... plt.plot(bins, y, linewidth=2, color='r') # doctest: +SKIP
... plt.show() # doctest: +SKIP
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