diff --git a/Full_cdt_one_plus/Pydocs/AlexanderMove.html b/Full Source Code of CDT (1+1)D/Pydocs/AlexanderMove.html similarity index 84% rename from Full_cdt_one_plus/Pydocs/AlexanderMove.html rename to Full Source Code of CDT (1+1)D/Pydocs/AlexanderMove.html index b88fc9c..e35d9aa 100644 --- a/Full_cdt_one_plus/Pydocs/AlexanderMove.html +++ b/Full Source Code of CDT (1+1)D/Pydocs/AlexanderMove.html @@ -8,10 +8,10 @@
Path: /Full_cdt_one_plus_one/moves/AlexanderMove.py
-Time-stamp: <2017-12-13 08:35:53 (Damodar)>
+Time-stamp: <2020-05-01 12:03:42 (edited by physicslog)>
Author: Damodar Rajbhandari (dphysicslog@gmail.com)
Description: This is a module where the Alexander move
@@ -94,7 +94,9 @@
class AlexanderMove(Move.AbstractMove)
-This class consists of the methods that define the Alexander
+AlexanderMove(pick_spacelike, share_tts_triangles)
+
+This class consists of the methods that define the Alexander
move.
Methods defined here:
+
+
self.pick_spacelike and delete the self.pick_spacelike.
i.e. [new_spacelike_edge_instances, new_vertex_instance]
@@ -185,7 +189,7 @@
-Data descriptors inherited from abc.ABC:
+Data descriptors inherited from Move.AbstractMove:
@@ -199,7 +203,7 @@
Functions
-
+
-
Draw samples from a Beta distribution.
@@ -210,7 +214,7 @@
.. math:: f(x; a,b) = \frac{1}{B(\alpha, \beta)} x^{\alpha - 1}
(1 - x)^{\beta - 1},
-where the normalisation, B, is the beta function,
+where the normalization, B, is the beta function,
.. math:: B(\alpha, \beta) = \int_0^1 t^{\alpha - 1}
(1 - t)^{\beta - 1} dt.
@@ -220,9 +224,9 @@
Parameters
----------
a : float or array_like of floats
- Alpha, non-negative.
+ Alpha, positive (>0).
b : float or array_like of floats
- Beta, non-negative.
+ Beta, positive (>0).
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),
@@ -233,7 +237,7 @@
-------
out : ndarray or scalar
Drawn samples from the parameterized beta distribution.
+
-
Draw samples from a binomial distribution.
@@ -295,7 +299,7 @@
Wolfram Web Resource.
http://mathworld.wolfram.com/BinomialDistribution.html
.. [5] Wikipedia, "Binomial distribution",
- http://en.wikipedia.org/wiki/Binomial_distribution
+ https://en.wikipedia.org/wiki/Binomial_distribution
Examples
--------
@@ -314,7 +318,7 @@
>>> sum(np.random.binomial(9, 0.1, 20000) == 0)/20000.
# answer = 0.38885, or 38%.
+
-
Return random bytes.
@@ -332,7 +336,7 @@
--------
>>> np.random.bytes(10)
' eh\x85\x022SZ\xbf\xa4' #random
+
-
Draw samples from a chi-square distribution.
@@ -343,8 +347,8 @@
Parameters
----------
-df : int or array_like of ints
- Number of degrees of freedom.
+df : float or array_like of floats
+ Number of degrees of freedom, must be > 0.
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),
@@ -385,20 +389,20 @@
References
----------
.. [1] NIST "Engineering Statistics Handbook"
- http://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
+ https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
Examples
--------
>>> np.random.chisquare(2,4)
-array([ 1.89920014, 9.00867716, 3.13710533, 5.62318272])
+
+array([ 1.89920014, 9.00867716, 3.13710533, 5.62318272]) # random
-
Generates a random sample from a given 1-D array
.. versionadded:: 1.7.0
Parameters
------------
+----------
a : 1-D array-like or int
If an ndarray, a random sample is generated from its elements.
If an int, the random sample is generated as if a were np.arange(a)
@@ -414,12 +418,12 @@
entries in a.
Returns
---------
+-------
samples : single item or ndarray
The generated random samples
Raises
--------
+------
ValueError
If a is an int and less than zero, if a or p are not 1-dimensional,
if a is an array-like of size 0, if p is not a vector of
@@ -428,50 +432,70 @@
size
See Also
----------
+--------
randint, shuffle, permutation
Examples
----------
+--------
Generate a uniform random sample from np.arange(5) of size 3:
>>> np.random.choice(5, 3)
-array([0, 3, 4])
+array([0, 3, 4]) # random
>>> #This is equivalent to np.random.randint(0,5,3)
Generate a non-uniform random sample from np.arange(5) of size 3:
>>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0])
-array([3, 3, 0])
+array([3, 3, 0]) # random
Generate a uniform random sample from np.arange(5) of size 3 without
replacement:
>>> np.random.choice(5, 3, replace=False)
-array([3,1,0])
+array([3,1,0]) # random
>>> #This is equivalent to np.random.permutation(np.arange(5))[:3]
Generate a non-uniform random sample from np.arange(5) of size
3 without replacement:
>>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0])
-array([2, 3, 0])
+array([2, 3, 0]) # random
Any of the above can be repeated with an arbitrary array-like
instead of just integers. For instance:
>>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher']
>>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3])
-array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'],
- dtype='|S11')
+
+array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'], # random
+ dtype='<U11')
+
+
+Parameters
+----------
+seed : {None, int, array_like[ints], ISeedSequence, BitGenerator, Generator}, optional
+ A seed to initialize the `BitGenerator`. If None, then fresh,
+ unpredictable entropy will be pulled from the OS. If an ``int`` or
+ ``array_like[ints]`` is passed, then it will be passed to
+ `SeedSequence` to derive the initial `BitGenerator` state. One may also
+ pass in an implementor of the `ISeedSequence` interface like
+ `SeedSequence`.
+ Additionally, when passed a `BitGenerator`, it will be wrapped by
+ `Generator`. If passed a `Generator`, it will be returned unaltered.
+
+Notes
+-----
+When `seed` is omitted or ``None``, a new `BitGenerator` and `Generator` will
+be instantiated each time. This function does not manage a default global
+instance.
-
Draw samples from the Dirichlet distribution.
Draw `size` samples of dimension k from a Dirichlet distribution. A
Dirichlet-distributed random variable can be seen as a multivariate
-generalization of a Beta distribution. Dirichlet pdf is the conjugate
-prior of a multinomial in Bayesian inference.
+generalization of a Beta distribution. The Dirichlet distribution
+is a conjugate prior of a multinomial distribution in Bayesian
+inference.
Parameters
----------
@@ -488,23 +512,38 @@
samples : ndarray,
The drawn samples, of shape (size, alpha.ndim).
+Raises
+-------
+ValueError
+ If any value in alpha is less than or equal to zero
+
Notes
-----
-.. math:: X \approx \prod_{i=1}^{k}{x^{\alpha_i-1}_i}
+The Dirichlet distribution is a distribution over vectors
+:math:`x` that fulfil the conditions :math:`x_i>0` and
+:math:`\sum_{i=1}^k x_i = 1`.
+
+The probability density function :math:`p` of a
+Dirichlet-distributed random vector :math:`X` is
+proportional to
+
+.. math:: p(x) \propto \prod_{i=1}^{k}{x^{\alpha_i-1}_i},
-Uses the following property for computation: for each dimension,
-draw a random sample y_i from a standard gamma generator of shape
-`alpha_i`, then
-:math:`X = \frac{1}{\sum_{i=1}^k{y_i}} (y_1, \ldots, y_n)` is
-Dirichlet distributed.
+where :math:`\alpha` is a vector containing the positive
+concentration parameters.
+
+The method uses the following property for computation: let :math:`Y`
+be a random vector which has components that follow a standard gamma
+distribution, then :math:`X = \frac{1}{\sum_{i=1}^k{Y_i}} Y`
+is Dirichlet-distributed
References
----------
.. [1] David McKay, "Information Theory, Inference and Learning
Algorithms," chapter 23,
- http://www.inference.phy.cam.ac.uk/mackay/
+ http://www.inference.org.uk/mackay/itila/
.. [2] Wikipedia, "Dirichlet distribution",
- http://en.wikipedia.org/wiki/Dirichlet_distribution
+ https://en.wikipedia.org/wiki/Dirichlet_distribution
Examples
--------
@@ -516,11 +555,12 @@
>>> s = np.random.dirichlet((10, 5, 3), 20).transpose()
+>>> import matplotlib.pyplot as plt
>>> plt.barh(range(20), s[0])
>>> plt.barh(range(20), s[1], left=s[0], color='g')
>>> plt.barh(range(20), s[2], left=s[0]+s[1], color='r')
>>> plt.title("Lengths of Strings")
+
-
Draw samples from an exponential distribution.
@@ -541,7 +581,8 @@
Parameters
----------
scale : float or array_like of floats
- The scale parameter, :math:`\beta = 1/\lambda`.
+ The scale parameter, :math:`\beta = 1/\lambda`. Must be
+ non-negative.
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),
@@ -558,16 +599,16 @@
.. [1] Peyton Z. Peebles Jr., "Probability, Random Variables and
Random Signal Principles", 4th ed, 2001, p. 57.
.. [2] Wikipedia, "Poisson process",
- http://en.wikipedia.org/wiki/Poisson_process
+ https://en.wikipedia.org/wiki/Poisson_process
.. [3] Wikipedia, "Exponential distribution",
- http://en.wikipedia.org/wiki/Exponential_distribution
+
+ https://en.wikipedia.org/wiki/Exponential_distribution
-
Draw samples from an F distribution.
Samples are drawn from an F distribution with specified parameters,
`dfnum` (degrees of freedom in numerator) and `dfden` (degrees of
-freedom in denominator), where both parameters should be greater than
+freedom in denominator), where both parameters must be greater than
zero.
The random variate of the F distribution (also known as the
@@ -577,10 +618,10 @@
Parameters
----------
-dfnum : int or array_like of ints
- Degrees of freedom in numerator. Should be greater than zero.
-dfden : int or array_like of ints
- Degrees of freedom in denominator. Should be greater than zero.
+dfnum : float or array_like of floats
+ Degrees of freedom in numerator, must be > 0.
+dfden : float or array_like of float
+ Degrees of freedom in denominator, must be > 0.
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),
@@ -612,7 +653,7 @@
.. [1] Glantz, Stanton A. "Primer of Biostatistics.", McGraw-Hill,
Fifth Edition, 2002.
.. [2] Wikipedia, "F-distribution",
- http://en.wikipedia.org/wiki/F-distribution
+ https://en.wikipedia.org/wiki/F-distribution
Examples
--------
@@ -634,13 +675,13 @@
The lower bound for the top 1% of the samples is :
->>> sort(s)[-10]
-7.61988120985
+>>> np.sort(s)[-10]
+7.61988120985 # random
So there is about a 1% chance that the F statistic will exceed 7.62,
the measured value is 36, so the null hypothesis is rejected at the 1%
level.
+
-
Draw samples from a Gamma distribution.
@@ -651,9 +692,9 @@
Parameters
----------
shape : float or array_like of floats
- The shape of the gamma distribution. Should be greater than zero.
+ The shape of the gamma distribution. Must be non-negative.
scale : float or array_like of floats, optional
- The scale of the gamma distribution. Should be greater than zero.
+ The scale of the gamma distribution. Must be non-negative.
Default is equal to 1.
size : int or tuple of ints, optional
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
@@ -690,7 +731,7 @@
Wolfram Web Resource.
http://mathworld.wolfram.com/GammaDistribution.html
.. [2] Wikipedia, "Gamma distribution",
- http://en.wikipedia.org/wiki/Gamma_distribution
+ https://en.wikipedia.org/wiki/Gamma_distribution
Examples
--------
@@ -703,13 +744,13 @@
the probability density function:
>>> import matplotlib.pyplot as plt
->>> import scipy.special as sps
->>> count, bins, ignored = plt.hist(s, 50, normed=True)
->>> y = bins**(shape-1)*(np.exp(-bins/scale) /
+>>> import scipy.special as sps # doctest: +SKIP
+>>> count, bins, ignored = plt.hist(s, 50, density=True)
+>>> y = bins**(shape-1)*(np.exp(-bins/scale) / # doctest: +SKIP
... (sps.gamma(shape)*scale**shape))
->>> plt.plot(bins, y, linewidth=2, color='r')
+>>> plt.plot(bins, y, linewidth=2, color='r') # doctest: +SKIP
>>> plt.show()
+
-
Draw samples from the geometric distribution.
@@ -751,7 +792,7 @@
>>> (z == 1).sum() / 10000.
0.34889999999999999 #random
+
-
Return a tuple representing the internal state of the generator.
@@ -759,7 +800,7 @@
Returns
-------
-out : tuple(str, ndarray of 624 uints, int, int, float)
+out : {tuple(str, ndarray of 624 uints, int, int, float), dict}
The returned tuple has the following items:
1. the string 'MT19937'.
@@ -768,6 +809,13 @@
4. an integer ``has_gauss``.
5. a float ``cached_gaussian``.
+ If `legacy` is False, or the BitGenerator is not NT19937, then
+ state is returned as a dictionary.
+
+legacy : bool
+ Flag indicating the return a legacy tuple state when the BitGenerator
+ is MT19937.
+
See Also
--------
set_state
@@ -777,7 +825,7 @@
`set_state` and `get_state` are not needed to work with any of the
random distributions in NumPy. If the internal state is manually altered,
the user should know exactly what he/she is doing.
+
-
Draw samples from a Gumbel distribution.
@@ -790,7 +838,8 @@
loc : float or array_like of floats, optional
The location of the mode of the distribution. Default is 0.
scale : float or array_like of floats, optional
- The scale parameter of the distribution. Default is 1.
+ The scale parameter of the distribution. Default is 1. Must be non-
+ negative.
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),
@@ -860,7 +909,7 @@
the probability density function:
>>> import matplotlib.pyplot as plt
->>> count, bins, ignored = plt.hist(s, 30, normed=True)
+>>> count, bins, ignored = plt.hist(s, 30, density=True)
>>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta)
... * np.exp( -np.exp( -(bins - mu) /beta) ),
... linewidth=2, color='r')
@@ -875,7 +924,7 @@
... a = np.random.normal(mu, beta, 1000)
... means.append(a.mean())
... maxima.append(a.max())
->>> count, bins, ignored = plt.hist(maxima, 30, normed=True)
+>>> count, bins, ignored = plt.hist(maxima, 30, density=True)
>>> beta = np.std(maxima) * np.sqrt(6) / np.pi
>>> mu = np.mean(maxima) - 0.57721*beta
>>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta)
@@ -885,14 +934,14 @@
... * np.exp(-(bins - mu)**2 / (2 * beta**2)),
... linewidth=2, color='g')
>>> plt.show()
+
-
Draw samples from a Hypergeometric distribution.
Samples are drawn from a hypergeometric distribution with specified
-parameters, ngood (ways to make a good selection), nbad (ways to make
-a bad selection), and nsample = number of items sampled, which is less
-than or equal to the sum ngood + nbad.
+parameters, `ngood` (ways to make a good selection), `nbad` (ways to make
+a bad selection), and `nsample` (number of items sampled, which is less
+than or equal to the sum ``ngood + nbad``).
Parameters
----------
@@ -906,14 +955,16 @@
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 ``ngood``, ``nbad``, and ``nsample``
+ a single value is returned if `ngood`, `nbad`, and `nsample`
are all scalars. Otherwise, ``np.broadcast(ngood, nbad, nsample).size``
samples are drawn.
Returns
-------
out : ndarray or scalar
- Drawn samples from the parameterized hypergeometric distribution.
+ Drawn samples from the parameterized hypergeometric distribution. Each
+ sample is the number of good items within a randomly selected subset of
+ size `nsample` taken from a set of `ngood` good items and `nbad` bad items.
See Also
--------
@@ -924,15 +975,15 @@
-----
The probability density for the Hypergeometric distribution is
-.. math:: P(x) = \frac{\binom{m}{n}\binom{N-m}{n-x}}{\binom{N}{n}},
+.. math:: P(x) = \frac{\binom{g}{x}\binom{b}{n-x}}{\binom{g+b}{n}},
-where :math:`0 \le x \le m` and :math:`n+m-N \le x \le n`
+where :math:`0 \le x \le n` and :math:`n-b \le x \le g`
-for P(x) the probability of x successes, n = ngood, m = nbad, and
-N = number of samples.
+for P(x) the probability of ``x`` good results in the drawn sample,
+g = `ngood`, b = `nbad`, and n = `nsample`.
-Consider an urn with black and white marbles in it, ngood of them
-black and nbad are white. If you draw nsample balls without
+Consider an urn with black and white marbles in it, `ngood` of them
+are black and `nbad` are white. If you draw `nsample` balls without
replacement, then the hypergeometric distribution describes the
distribution of black balls in the drawn sample.
@@ -950,7 +1001,7 @@
MathWorld--A Wolfram Web Resource.
http://mathworld.wolfram.com/HypergeometricDistribution.html
.. [3] Wikipedia, "Hypergeometric distribution",
- http://en.wikipedia.org/wiki/Hypergeometric_distribution
+ https://en.wikipedia.org/wiki/Hypergeometric_distribution
Examples
--------
@@ -959,6 +1010,7 @@
>>> ngood, nbad, nsamp = 100, 2, 10
# number of good, number of bad, and number of samples
>>> s = np.random.hypergeometric(ngood, nbad, nsamp, 1000)
+>>> from matplotlib.pyplot import hist
>>> hist(s)
# note that it is very unlikely to grab both bad items
@@ -969,7 +1021,7 @@
>>> s = np.random.hypergeometric(15, 15, 15, 100000)
>>> sum(s>=12)/100000. + sum(s<=3)/100000.
# answer = 0.003 ... pretty unlikely!
+
-
Draw samples from the Laplace or double exponential distribution with
specified location (or mean) and scale (decay).
@@ -984,7 +1036,8 @@
loc : float or array_like of floats, optional
The position, :math:`\mu`, of the distribution peak. Default is 0.
scale : float or array_like of floats, optional
- :math:`\lambda`, the exponential decay. Default is 1.
+ :math:`\lambda`, the exponential decay. Default is 1. Must be non-
+ negative.
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),
@@ -1021,7 +1074,7 @@
From MathWorld--A Wolfram Web Resource.
http://mathworld.wolfram.com/LaplaceDistribution.html
.. [4] Wikipedia, "Laplace distribution",
- http://en.wikipedia.org/wiki/Laplace_distribution
+ https://en.wikipedia.org/wiki/Laplace_distribution
Examples
--------
@@ -1034,7 +1087,7 @@
the probability density function:
>>> import matplotlib.pyplot as plt
->>> count, bins, ignored = plt.hist(s, 30, normed=True)
+>>> 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)
@@ -1044,7 +1097,7 @@
>>> g = (1/(scale * np.sqrt(2 * np.pi)) *
... np.exp(-(x - loc)**2 / (2 * scale**2)))
>>> plt.plot(x,g)
+
-
Draw samples from a logistic distribution.
@@ -1056,7 +1109,7 @@
loc : float or array_like of floats, optional
Parameter of the distribution. Default is 0.
scale : float or array_like of floats, optional
- Parameter of the distribution. Should be greater than zero.
+ Parameter of the 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
@@ -1097,7 +1150,7 @@
MathWorld--A Wolfram Web Resource.
http://mathworld.wolfram.com/LogisticDistribution.html
.. [3] Wikipedia, "Logistic-distribution",
- http://en.wikipedia.org/wiki/Logistic_distribution
+ https://en.wikipedia.org/wiki/Logistic_distribution
Examples
--------
@@ -1105,16 +1158,17 @@
>>> loc, scale = 10, 1
>>> s = np.random.logistic(loc, scale, 10000)
+>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, bins=50)
# plot against distribution
>>> def logist(x, loc, scale):
-... return exp((loc-x)/scale)/(scale*(1+exp((loc-x)/scale))**2)
->>> plt.plot(bins, logist(bins, loc, scale)*count.max()/\
-... logist(bins, loc, scale).max())
+... return np.exp((loc-x)/scale)/(scale*(1+np.exp((loc-x)/scale))**2)
+>>> lgst_val = logist(bins, loc, scale)
+>>> plt.plot(bins, lgst_val * count.max() / lgst_val.max())
>>> plt.show()
+
-
Draw samples from a log-normal distribution.
@@ -1128,8 +1182,8 @@
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. Should
- be greater than zero. Default is 1.
+ 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),
@@ -1168,7 +1222,7 @@
.. [1] Limpert, E., Stahel, W. A., and Abbt, M., "Log-normal
Distributions across the Sciences: Keys and Clues,"
BioScience, Vol. 51, No. 5, May, 2001.
- http://stat.ethz.ch/~stahel/lognormal/bioscience.pdf
+ https://stat.ethz.ch/~stahel/lognormal/bioscience.pdf
.. [2] Reiss, R.D. and Thomas, M., "Statistical Analysis of Extreme
Values," Basel: Birkhauser Verlag, 2001, pp. 31-32.
@@ -1183,7 +1237,7 @@
the probability density function:
>>> import matplotlib.pyplot as plt
->>> count, bins, ignored = plt.hist(s, 100, normed=True, align='mid')
+>>> count, bins, ignored = plt.hist(s, 100, density=True, align='mid')
>>> x = np.linspace(min(bins), max(bins), 10000)
>>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2))
@@ -1201,11 +1255,11 @@
>>> # values, drawn from a normal distribution.
>>> b = []
>>> for i in range(1000):
-... a = 10. + np.random.random(100)
+... a = 10. + np.random.standard_normal(100)
... b.append(np.product(a))
>>> b = np.array(b) / np.min(b) # scale values to be positive
->>> count, bins, ignored = plt.hist(b, 100, normed=True, align='mid')
+>>> count, bins, ignored = plt.hist(b, 100, density=True, align='mid')
>>> sigma = np.std(np.log(b))
>>> mu = np.mean(np.log(b))
@@ -1215,7 +1269,7 @@
>>> plt.plot(x, pdf, color='r', linewidth=2)
>>> plt.show()
+
-
Draw samples from a logarithmic series distribution.
@@ -1268,7 +1322,7 @@
.. [3] D. J. Hand, F. Daly, D. Lunn, E. Ostrowski, A Handbook of Small
Data Sets, CRC Press, 1994.
.. [4] Wikipedia, "Logarithmic distribution",
- http://en.wikipedia.org/wiki/Logarithmic_distribution
+ https://en.wikipedia.org/wiki/Logarithmic_distribution
Examples
--------
@@ -1276,20 +1330,21 @@
>>> a = .6
>>> s = np.random.logseries(a, 10000)
+>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s)
# plot against distribution
>>> def logseries(k, p):
-... return -p**k/(k*log(1-p))
+... return -p**k/(k*np.log(1-p))
>>> plt.plot(bins, logseries(bins, a)*count.max()/
- logseries(bins, a).max(), 'r')
+... logseries(bins, a).max(), 'r')
>>> plt.show()
+
-
Draw samples from a multinomial distribution.
-The multinomial distribution is a multivariate generalisation of the
+The multinomial distribution is a multivariate generalization of the
binomial distribution. Take an experiment with one of ``p``
possible outcomes. An example of such an experiment is throwing a dice,
where the outcome can be 1 through 6. Each sample drawn from the
@@ -1303,7 +1358,7 @@
Number of experiments.
pvals : sequence of floats, length p
Probabilities of each of the ``p`` different outcomes. These
- should sum to 1 (however, the last element is always assumed to
+ must sum to 1 (however, the last element is always assumed to
account for the remaining probability, as long as
``sum(pvals[:-1]) <= 1)``.
size : int or tuple of ints, optional
@@ -1325,14 +1380,14 @@
Throw a dice 20 times:
>>> np.random.multinomial(20, [1/6.]*6, size=1)
-array([[4, 1, 7, 5, 2, 1]])
+array([[4, 1, 7, 5, 2, 1]]) # random
It landed 4 times on 1, once on 2, etc.
Now, throw the dice 20 times, and 20 times again:
>>> np.random.multinomial(20, [1/6.]*6, size=2)
-array([[3, 4, 3, 3, 4, 3],
+array([[3, 4, 3, 3, 4, 3], # random
[2, 4, 3, 4, 0, 7]])
For the first run, we threw 3 times 1, 4 times 2, etc. For the second,
@@ -1341,7 +1396,7 @@
A loaded die is more likely to land on number 6:
>>> np.random.multinomial(100, [1/7.]*5 + [2/7.])
-array([11, 16, 14, 17, 16, 26])
+array([11, 16, 14, 17, 16, 26]) # random
The probability inputs should be normalized. As an implementation
detail, the value of the last entry is ignored and assumed to take
@@ -1350,13 +1405,14 @@
other should be sampled like so:
>>> np.random.multinomial(100, [1.0 / 3, 2.0 / 3]) # RIGHT
-array([38, 62])
+array([38, 62]) # random
not like:
>>> np.random.multinomial(100, [1.0, 2.0]) # WRONG
-array([100, 0])
+
+Traceback (most recent call last):
+ValueError: pvals < 0, pvals > 1 or pvals contains NaNs
-
Draw random samples from a multivariate normal distribution.
@@ -1383,6 +1439,7 @@
Behavior when the covariance matrix is not positive semidefinite.
tol : float, optional
Tolerance when checking the singular values in covariance matrix.
+ cov is cast to double before the check.
Returns
-------
@@ -1451,20 +1508,19 @@
standard deviation:
>>> list((x[0,0,:] - mean) < 0.6)
-[True, True]
+
+[True, True] # random
-
Draw samples from a negative binomial distribution.
Samples are drawn from a negative binomial distribution with specified
-parameters, `n` trials and `p` probability of success where `n` is an
-integer > 0 and `p` is in the interval [0, 1].
+parameters, `n` successes and `p` probability of success where `n`
+is > 0 and `p` is in the interval [0, 1].
Parameters
----------
-n : int or array_like of ints
- Parameter of the distribution, > 0. Floats are also accepted,
- but they will be truncated to integers.
+n : float or array_like of floats
+ Parameter of the distribution, > 0.
p : float or array_like of floats
Parameter of the distribution, >= 0 and <=1.
size : int or tuple of ints, optional
@@ -1477,21 +1533,22 @@
-------
out : ndarray or scalar
Drawn samples from the parameterized negative binomial distribution,
- where each sample is equal to N, the number of trials it took to
- achieve n - 1 successes, N - (n - 1) failures, and a success on the,
- (N + n)th trial.
+ where each sample is equal to N, the number of failures that
+ occurred before a total of n successes was reached.
Notes
-----
-The probability density for the negative binomial distribution is
+The probability mass function of the negative binomial distribution is
-.. math:: P(N;n,p) = \binom{N+n-1}{n-1}p^{n}(1-p)^{N},
+.. math:: P(N;n,p) = \frac{\Gamma(N+n)}{N!\Gamma(n)}p^{n}(1-p)^{N},
-where :math:`n-1` is the number of successes, :math:`p` is the
-probability of success, and :math:`N+n-1` is the number of trials.
-The negative binomial distribution gives the probability of n-1
-successes and N failures in N+n-1 trials, and success on the (N+n)th
-trial.
+where :math:`n` is the number of successes, :math:`p` is the
+probability of success, :math:`N+n` is the number of trials, and
+:math:`\Gamma` is the gamma function. When :math:`n` is an integer,
+:math:`\frac{\Gamma(N+n)}{N!\Gamma(n)} = \binom{N+n-1}{N}`, which is
+the more common form of this term in the the pmf. The negative
+binomial distribution gives the probability of N failures given n
+successes, with a success on the last trial.
If one throws a die repeatedly until the third time a "1" appears,
then the probability distribution of the number of non-"1"s that
@@ -1503,7 +1560,7 @@
MathWorld--A Wolfram Web Resource.
http://mathworld.wolfram.com/NegativeBinomialDistribution.html
.. [2] Wikipedia, "Negative binomial distribution",
- http://en.wikipedia.org/wiki/Negative_binomial_distribution
+ https://en.wikipedia.org/wiki/Negative_binomial_distribution
Examples
--------
@@ -1516,23 +1573,25 @@
single success after drilling 5 wells, after 6 wells, etc.?
>>> s = np.random.negative_binomial(1, 0.1, 100000)
->>> for i in range(1, 11):
+>>> for i in range(1, 11): # doctest: +SKIP
... probability = sum(s<i) / 100000.
-... print i, "wells drilled, probability of one success =", probability
+
+... print(i, "wells drilled, probability of one success =", probability)
-
Draw samples from a noncentral chi-square distribution.
-The noncentral :math:`\chi^2` distribution is a generalisation of
+The noncentral :math:`\chi^2` distribution is a generalization of
the :math:`\chi^2` distribution.
Parameters
----------
-df : int or array_like of ints
- Degrees of freedom, should be > 0 as of NumPy 1.10.0,
- should be > 1 for earlier versions.
+df : float or array_like of floats
+ Degrees of freedom, must be > 0.
+
+ .. versionchanged:: 1.10.0
+ Earlier NumPy versions required dfnum > 1.
nonc : float or array_like of floats
- Non-centrality, should be non-negative.
+ Non-centrality, must be non-negative.
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),
@@ -1551,22 +1610,14 @@
.. math:: P(x;df,nonc) = \sum^{\infty}_{i=0}
\frac{e^{-nonc/2}(nonc/2)^{i}}{i!}
- \P_{Y_{df+2i}}(x),
+ P_{Y_{df+2i}}(x),
where :math:`Y_{q}` is the Chi-square with q degrees of freedom.
-In Delhi (2007), it is noted that the noncentral chi-square is
-useful in bombing and coverage problems, the probability of
-killing the point target given by the noncentral chi-squared
-distribution.
-
References
----------
-.. [1] Delhi, M.S. Holla, "On a noncentral chi-square distribution in
- the analysis of weapon systems effectiveness", Metrika,
- Volume 15, Number 1 / December, 1970.
-.. [2] Wikipedia, "Noncentral chi-square distribution"
- http://en.wikipedia.org/wiki/Noncentral_chi-square_distribution
+.. [1] Wikipedia, "Noncentral chi-squared distribution"
+ https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution
Examples
--------
@@ -1574,7 +1625,7 @@
>>> import matplotlib.pyplot as plt
>>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),
-... bins=200, normed=True)
+... bins=200, density=True)
>>> plt.show()
Draw values from a noncentral chisquare with very small noncentrality,
@@ -1582,9 +1633,9 @@
>>> plt.figure()
>>> values = plt.hist(np.random.noncentral_chisquare(3, .0000001, 100000),
-... bins=np.arange(0., 25, .1), normed=True)
+... bins=np.arange(0., 25, .1), density=True)
>>> values2 = plt.hist(np.random.chisquare(3, 100000),
-... bins=np.arange(0., 25, .1), normed=True)
+... bins=np.arange(0., 25, .1), density=True)
>>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob')
>>> plt.show()
@@ -1593,9 +1644,9 @@
>>> plt.figure()
>>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),
-... bins=200, normed=True)
+... bins=200, density=True)
>>> plt.show()
+
-
Draw samples from the noncentral F distribution.
@@ -1606,12 +1657,16 @@
Parameters
----------
-dfnum : int or array_like of ints
- Parameter, should be > 1.
-dfden : int or array_like of ints
- Parameter, should be > 1.
+dfnum : float or array_like of floats
+ Numerator degrees of freedom, must be > 0.
+
+ .. versionchanged:: 1.14.0
+ Earlier NumPy versions required dfnum > 1.
+dfden : float or array_like of floats
+ Denominator degrees of freedom, must be > 0.
nonc : float or array_like of floats
- Parameter, should be >= 0.
+ Non-centrality parameter, the sum of the squares of the numerator
+ means, must be >= 0.
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),
@@ -1638,7 +1693,7 @@
From MathWorld--A Wolfram Web Resource.
http://mathworld.wolfram.com/NoncentralF-Distribution.html
.. [2] Wikipedia, "Noncentral F-distribution",
- http://en.wikipedia.org/wiki/Noncentral_F-distribution
+ https://en.wikipedia.org/wiki/Noncentral_F-distribution
Examples
--------
@@ -1652,13 +1707,14 @@
>>> dfden = 20 # within groups degrees of freedom
>>> nonc = 3.0
>>> nc_vals = np.random.noncentral_f(dfnum, dfden, nonc, 1000000)
->>> NF = np.histogram(nc_vals, bins=50, normed=True)
+>>> NF = np.histogram(nc_vals, bins=50, density=True)
>>> c_vals = np.random.f(dfnum, dfden, 1000000)
->>> F = np.histogram(c_vals, bins=50, normed=True)
+>>> F = np.histogram(c_vals, bins=50, density=True)
+>>> import matplotlib.pyplot as plt
>>> plt.plot(F[1][1:], F[0])
>>> plt.plot(NF[1][1:], NF[0])
>>> plt.show()
+
-
Draw random samples from a normal (Gaussian) distribution.
@@ -1677,7 +1733,8 @@
loc : float or array_like of floats
Mean ("centre") of the distribution.
scale : float or array_like of floats
- Standard deviation (spread or "width") of the distribution.
+ Standard deviation (spread or "width") of the distribution. Must be
+ non-negative.
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),
@@ -1714,7 +1771,7 @@
References
----------
.. [1] Wikipedia, "Normal distribution",
- http://en.wikipedia.org/wiki/Normal_distribution
+ https://en.wikipedia.org/wiki/Normal_distribution
.. [2] P. R. Peebles Jr., "Central Limit Theorem" in "Probability,
Random Variables and Random Signal Principles", 4th ed., 2001,
pp. 51, 51, 125.
@@ -1728,22 +1785,28 @@
Verify the mean and the variance:
->>> abs(mu - np.mean(s)) < 0.01
-True
+>>> abs(mu - np.mean(s))
+0.0 # may vary
->>> abs(sigma - np.std(s, ddof=1)) < 0.01
-True
+>>> abs(sigma - np.std(s, ddof=1))
+0.1 # may vary
Display the histogram of the samples, along with
the probability density function:
>>> import matplotlib.pyplot as plt
->>> count, bins, ignored = plt.hist(s, 30, normed=True)
+>>> count, bins, ignored = plt.hist(s, 30, density=True)
>>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *
... np.exp( - (bins - mu)**2 / (2 * sigma**2) ),
... linewidth=2, color='r')
->>> plt.show()
+
+>>> plt.show()
+
+Two-by-four array of samples from N(3, 6.25):
+
+>>> np.random.normal(3, 2.5, size=(2, 4))
+array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random
+ [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random
-
Draw samples from a Pareto II or Lomax distribution with
specified shape.
@@ -1768,7 +1831,7 @@
Parameters
----------
a : float or array_like of floats
- Shape of the distribution. Should be greater than zero.
+ Shape of the distribution. Must be positive.
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),
@@ -1806,7 +1869,6 @@
projects in Sourceforge [1]_. It is one of the so-called
"fat-tailed" distributions.
-
References
----------
.. [1] Francis Hunt and Paul Johnson, On the Pareto Distribution of
@@ -1815,7 +1877,7 @@
.. [3] Reiss, R.D., Thomas, M.(2001), Statistical Analysis of Extreme
Values, Birkhauser Verlag, Basel, pp 23-30.
.. [4] Wikipedia, "Pareto distribution",
- http://en.wikipedia.org/wiki/Pareto_distribution
+ https://en.wikipedia.org/wiki/Pareto_distribution
Examples
--------
@@ -1828,11 +1890,11 @@
density function:
>>> import matplotlib.pyplot as plt
->>> count, bins, _ = plt.hist(s, 100, normed=True)
+>>> count, bins, _ = plt.hist(s, 100, density=True)
>>> fit = a*m**a / bins**(a+1)
>>> plt.plot(bins, max(count)*fit/max(fit), linewidth=2, color='r')
>>> plt.show()
+
-
Randomly permute a sequence, or return a permuted range.
@@ -1851,20 +1913,21 @@
out : ndarray
Permuted sequence or array range.
+
Examples
--------
>>> np.random.permutation(10)
-array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6])
+array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6]) # random
>>> np.random.permutation([1, 4, 9, 12, 15])
-array([15, 1, 9, 4, 12])
+array([15, 1, 9, 4, 12]) # random
>>> arr = np.arange(9).reshape((3, 3))
>>> np.random.permutation(arr)
-array([[6, 7, 8],
+array([[6, 7, 8], # random
[0, 1, 2],
[3, 4, 5]])
+
-
Draw samples from a Poisson distribution.
@@ -1874,7 +1937,7 @@
Parameters
----------
lam : float or array_like of floats
- Expectation of interval, should be >= 0. A sequence of expectation
+ Expectation of interval, must be >= 0. A sequence of expectation
intervals must be broadcastable over the requested size.
size : int or tuple of ints, optional
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
@@ -1898,7 +1961,7 @@
:math:`k` events occurring within the observed
interval :math:`\lambda`.
-Because the output is limited to the range of the C long type, a
+Because the output is limited to the range of the C int64 type, a
ValueError is raised when `lam` is within 10 sigma of the maximum
representable value.
@@ -1908,7 +1971,7 @@
From MathWorld--A Wolfram Web Resource.
http://mathworld.wolfram.com/PoissonDistribution.html
.. [2] Wikipedia, "Poisson distribution",
- http://en.wikipedia.org/wiki/Poisson_distribution
+ https://en.wikipedia.org/wiki/Poisson_distribution
Examples
--------
@@ -1920,13 +1983,13 @@
Display histogram of the sample:
>>> import matplotlib.pyplot as plt
->>> count, bins, ignored = plt.hist(s, 14, normed=True)
+>>> count, bins, ignored = plt.hist(s, 14, density=True)
>>> plt.show()
Draw each 100 values for lambda 100 and 500:
>>> s = np.random.poisson(lam=(100., 500.), size=(100, 2))
+
-
Draws samples in [0, 1] from a power distribution with positive
exponent a - 1.
@@ -1936,7 +1999,7 @@
Parameters
----------
a : float or array_like of floats
- Parameter of the distribution. Should be greater than zero.
+ Parameter of the distribution. Must be non-negative.
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),
@@ -1974,7 +2037,7 @@
Dataplot Reference Manual, Volume 2: Let Subcommands and Library
Functions", National Institute of Standards and Technology
Handbook Series, June 2003.
- http://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/powpdf.pdf
+ https://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/powpdf.pdf
Examples
--------
@@ -1997,30 +2060,36 @@
Compare the power function distribution to the inverse of the Pareto.
->>> from scipy import stats
+>>> from scipy import stats # doctest: +SKIP
>>> rvs = np.random.power(5, 1000000)
>>> rvsp = np.random.pareto(5, 1000000)
>>> xx = np.linspace(0,1,100)
->>> powpdf = stats.powerlaw.pdf(xx,5)
+>>> powpdf = stats.powerlaw.pdf(xx,5) # doctest: +SKIP
>>> plt.figure()
->>> plt.hist(rvs, bins=50, normed=True)
->>> plt.plot(xx,powpdf,'r-')
+>>> plt.hist(rvs, bins=50, density=True)
+>>> plt.plot(xx,powpdf,'r-') # doctest: +SKIP
>>> plt.title('np.random.power(5)')
>>> plt.figure()
->>> plt.hist(1./(1.+rvsp), bins=50, normed=True)
->>> plt.plot(xx,powpdf,'r-')
+>>> plt.hist(1./(1.+rvsp), bins=50, density=True)
+>>> plt.plot(xx,powpdf,'r-') # doctest: +SKIP
>>> plt.title('inverse of 1 + np.random.pareto(5)')
>>> plt.figure()
->>> plt.hist(1./(1.+rvsp), bins=50, normed=True)
->>> plt.plot(xx,powpdf,'r-')
+>>> plt.hist(1./(1.+rvsp), bins=50, density=True)
+>>> plt.plot(xx,powpdf,'r-') # doctest: +SKIP
>>> plt.title('inverse of stats.pareto(5)')
+
-
Random values in a given shape.
+.. note::
+ This is a convenience function for users porting code from Matlab,
+ and wraps `numpy.random.random_sample`. That function takes a
+ tuple to specify the size of the output, which is consistent with
+ other NumPy functions like `numpy.zeros` and `numpy.ones`.
+
Create an array of the given shape and populate it with
random samples from a uniform distribution
over ``[0, 1)``.
@@ -2028,7 +2097,7 @@
Parameters
----------
d0, d1, ..., dn : int, optional
- The dimensions of the returned array, should all be positive.
+ The dimensions of the returned array, must be non-negative.
If no argument is given a single Python float is returned.
Returns
@@ -2040,19 +2109,13 @@
--------
random
-Notes
------
-This is a convenience function. If you want an interface that
-takes a shape-tuple as the first argument, refer to
-np.random.random_sample .
-
Examples
--------
>>> np.random.rand(3,2)
array([[ 0.14022471, 0.96360618], #random
[ 0.37601032, 0.25528411], #random
[ 0.49313049, 0.94909878]]) #random
+
-
Return random integers from `low` (inclusive) to `high` (exclusive).
@@ -2062,13 +2125,14 @@
Parameters
----------
-low : int
- Lowest (signed) integer to be drawn from the distribution (unless
+low : int or array-like of ints
+ Lowest (signed) integers to be drawn from the distribution (unless
``high=None``, in which case this parameter is one above the
*highest* such integer).
-high : int, optional
+high : int or array-like of ints, optional
If provided, one above the largest (signed) integer to be drawn
from the distribution (see above for behavior if ``high=None``).
+ If array-like, must contain integer values
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. Default is None, in which case a
@@ -2091,40 +2155,56 @@
--------
random.random_integers : similar to `randint`, only for the closed
interval [`low`, `high`], and 1 is the lowest value if `high` is
- omitted. In particular, this other one is the one to use to generate
- uniformly distributed discrete non-integers.
+ omitted.
Examples
--------
>>> np.random.randint(2, size=10)
-array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])
+array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) # random
>>> np.random.randint(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Generate a 2 x 4 array of ints between 0 and 4, inclusive:
>>> np.random.randint(5, size=(2, 4))
-array([[4, 0, 2, 1],
- [3, 2, 2, 0]])
+
+array([[4, 0, 2, 1], # random
+ [3, 2, 2, 0]])
+
+Generate a 1 x 3 array with 3 different upper bounds
+
+>>> np.random.randint(1, [3, 5, 10])
+array([2, 2, 9]) # random
+
+Generate a 1 by 3 array with 3 different lower bounds
+
+>>> np.random.randint([1, 5, 7], 10)
+array([9, 8, 7]) # random
+
+Generate a 2 by 4 array using broadcasting with dtype of uint8
+
+>>> np.random.randint([1, 3, 5, 7], [[10], [20]], dtype=np.uint8)
+array([[ 8, 6, 9, 7], # random
+ [ 1, 16, 9, 12]], dtype=uint8)
-
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 :math:`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.
+.. note::
+ This is a convenience function for users porting code from Matlab,
+ and wraps `numpy.random.standard_normal`. That function takes a
+ tuple to specify the size of the output, which is consistent with
+ other NumPy functions like `numpy.zeros` and `numpy.ones`.
-This is a convenience function. If you want an interface that takes a
-tuple as the first argument, use `numpy.random.standard_normal` instead.
+If positive int_like 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. A single float randomly sampled
+from the distribution is returned if no argument is provided.
Parameters
----------
d0, d1, ..., dn : int, optional
- The dimensions of the returned array, should be all positive.
+ The dimensions of the returned array, must be non-negative.
If no argument is given a single Python float is returned.
Returns
@@ -2136,7 +2216,8 @@
See Also
--------
-random.standard_normal : Similar, but takes a tuple as its argument.
+standard_normal : Similar, but takes a tuple as its argument.
+normal : Also accepts mu and sigma arguments.
Notes
-----
@@ -2147,60 +2228,26 @@
Examples
--------
>>> np.random.randn()
-2.1923875335537315 #random
+2.1923875335537315 # random
Two-by-four array of samples from N(3, 6.25):
->>> 2.5 * np.random.randn(2, 4) + 3
-array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], #random
- [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) #random
+
-
-Return random floats in the half-open interval [0.0, 1.0).
-
-Results are from the "continuous uniform" distribution over the
-stated interval. To sample :math:`Unif[a, b), b > a` multiply
-the output of `random_sample` by `(b-a)` and add `a`::
-
- (b - a) * random_sample() + a
-
-Parameters
-----------
-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. Default is None, in which case a
- single value is returned.
-
-Returns
--------
-out : float or ndarray of floats
- Array of random floats of shape `size` (unless ``size=None``, in which
- case a single float is returned).
-
-Examples
---------
->>> np.random.random_sample()
-0.47108547995356098
->>> type(np.random.random_sample())
-<type 'float'>
->>> np.random.random_sample((5,))
-array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428])
-
-Three-by-two array of random numbers from [-5, 0):
+>>> 3 + 2.5 * np.random.randn(2, 4)
+array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random
+ [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random
-
->>> 5 * np.random.random_sample((3, 2)) - 5
-array([[-3.99149989, -0.52338984],
- [-2.99091858, -0.79479508],
- [-1.23204345, -1.75224494]])
+
+Return random floats in the half-open interval [0.0, 1.0). Alias for
+`random_sample` to ease forward-porting to the new random API.
-
Random integers of type np.int between `low` and `high`, inclusive.
Return random integers of type np.int from the "discrete uniform"
distribution in the closed interval [`low`, `high`]. If `high` is
None (the default), then results are from [1, `low`]. The np.int
-type translates to the C long type used by Python 2 for "short"
-integers and its precision is platform dependent.
+type translates to the C long integer type and its precision
+is platform dependent.
This function has been deprecated. Use randint instead.
@@ -2228,7 +2275,7 @@
See Also
--------
-random.randint : Similar to `random_integers`, only for the half-open
+randint : Similar to `random_integers`, only for the half-open
interval [`low`, `high`), and 0 is the lowest value if `high` is
omitted.
@@ -2242,11 +2289,11 @@
Examples
--------
>>> np.random.random_integers(5)
-4
+4 # random
>>> type(np.random.random_integers(5))
-<type 'int'>
+<class 'numpy.int64'>
>>> np.random.random_integers(5, size=(3,2))
-array([[5, 4],
+array([[5, 4], # random
[3, 3],
[4, 5]])
@@ -2255,7 +2302,7 @@
:math:`{0, 5/8, 10/8, 15/8, 20/8}`):
>>> 2.5 * (np.random.random_integers(5, size=(5,)) - 1) / 4.
-array([ 0.625, 1.25 , 0.625, 0.625, 2.5 ])
+array([ 0.625, 1.25 , 0.625, 0.625, 2.5 ]) # random
Roll two six sided dice 1000 times and sum the results:
@@ -2266,9 +2313,9 @@
Display results as a histogram:
>>> import matplotlib.pyplot as plt
->>> count, bins, ignored = plt.hist(dsums, 11, normed=True)
+>>> count, bins, ignored = plt.hist(dsums, 11, density=True)
>>> plt.show()
+
-
Return random floats in the half-open interval [0.0, 1.0).
@@ -2294,57 +2341,21 @@
Examples
--------
>>> np.random.random_sample()
-0.47108547995356098
+0.47108547995356098 # random
>>> type(np.random.random_sample())
-<type 'float'>
+<class 'float'>
>>> np.random.random_sample((5,))
-array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428])
+array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428]) # random
Three-by-two array of random numbers from [-5, 0):
>>> 5 * np.random.random_sample((3, 2)) - 5
-array([[-3.99149989, -0.52338984],
+array([[-3.99149989, -0.52338984], # random
[-2.99091858, -0.79479508],
[-1.23204345, -1.75224494]])
-
-
-Return random floats in the half-open interval [0.0, 1.0).
-
-Results are from the "continuous uniform" distribution over the
-stated interval. To sample :math:`Unif[a, b), b > a` multiply
-the output of `random_sample` by `(b-a)` and add `a`::
-
- (b - a) * random_sample() + a
-
-Parameters
-----------
-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. Default is None, in which case a
- single value is returned.
-
-Returns
--------
-out : float or ndarray of floats
- Array of random floats of shape `size` (unless ``size=None``, in which
- case a single float is returned).
-
-Examples
---------
->>> np.random.random_sample()
-0.47108547995356098
->>> type(np.random.random_sample())
-<type 'float'>
->>> np.random.random_sample((5,))
-array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428])
-
-Three-by-two array of random numbers from [-5, 0):
-
->>> 5 * np.random.random_sample((3, 2)) - 5
-array([[-3.99149989, -0.52338984],
- [-2.99091858, -0.79479508],
- [-1.23204345, -1.75224494]])
+
+
+documentation.
+0.087300000000000003 # random
Draw samples from a Rayleigh distribution.
@@ -2354,7 +2365,7 @@
Parameters
----------
scale : float or array_like of floats, optional
- Scale, also equals the mode. Should be >= 0. Default is 1.
+ Scale, also equals the mode. 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),
@@ -2380,15 +2391,16 @@
References
----------
.. [1] Brighton Webs Ltd., "Rayleigh Distribution,"
- http://www.brighton-webs.co.uk/distributions/rayleigh.asp
+ https://web.archive.org/web/20090514091424/http://brighton-webs.co.uk:80/distributions/rayleigh.asp
.. [2] Wikipedia, "Rayleigh distribution"
- http://en.wikipedia.org/wiki/Rayleigh_distribution
+ https://en.wikipedia.org/wiki/Rayleigh_distribution
Examples
--------
Draw values from the distribution and plot the histogram
->>> values = hist(np.random.rayleigh(3, 100000), bins=200, normed=True)
+>>> from matplotlib.pyplot import hist
+>>> values = hist(np.random.rayleigh(3, 100000), bins=200, density=True)
Wave heights tend to follow a Rayleigh distribution. If the mean wave
height is 1 meter, what fraction of waves are likely to be larger than 3
@@ -2401,7 +2413,7 @@
The percentage of waves larger than 3 meters is:
>>> 100.*sum(s>3)/1000000.
-0.087300000000000003
-
Apply a function of two arguments cumulatively to the items of a sequence,
@@ -2410,70 +2422,37 @@
((((1+2)+3)+4)+5). If initial is present, it is placed before the items
of the sequence in the calculation, and serves as a default when the
sequence is empty.
+
+
+documentation.
-
-Return random floats in the half-open interval [0.0, 1.0).
+Reseed a legacy MT19937 BitGenerator
-Results are from the "continuous uniform" distribution over the
-stated interval. To sample :math:`Unif[a, b), b > a` multiply
-the output of `random_sample` by `(b-a)` and add `a`::
-
- (b - a) * random_sample() + a
-
-Parameters
-----------
-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. Default is None, in which case a
- single value is returned.
-
-Returns
--------
-out : float or ndarray of floats
- Array of random floats of shape `size` (unless ``size=None``, in which
- case a single float is returned).
-
-Examples
---------
->>> np.random.random_sample()
-0.47108547995356098
->>> type(np.random.random_sample())
-<type 'float'>
->>> np.random.random_sample((5,))
-array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428])
-
-Three-by-two array of random numbers from [-5, 0):
-
->>> 5 * np.random.random_sample((3, 2)) - 5
-array([[-3.99149989, -0.52338984],
- [-2.99091858, -0.79479508],
- [-1.23204345, -1.75224494]])
-
-
-Seed the generator.
+Notes
+-----
+This is a convenience, legacy function.
-This method is called when `RandomState` is initialized. It can be
-called again to re-seed the generator. For details, see `RandomState`.
+The best practice is to **not** reseed a BitGenerator, rather to
+recreate a new one. This method is here for legacy reasons.
+This example demonstrates best practice.
-Parameters
-----------
-seed : int or array_like, optional
- Seed for `RandomState`.
- Must be convertible to 32 bit unsigned integers.
-
-See Also
---------
-RandomState
+
+>>> from numpy.random import MT19937
+>>> from numpy.random import RandomState, SeedSequence
+>>> rs = RandomState(MT19937(SeedSequence(123456789)))
+# Later, you want to restart the stream
+>>> rs = RandomState(MT19937(SeedSequence(987654321)))
-
Set the internal state of the generator from a tuple.
-For use if one has reason to manually (re-)set the internal state of the
-"Mersenne Twister"[1]_ pseudo-random number generating algorithm.
+For use if one has reason to manually (re-)set the internal state of
+the bit generator used by the RandomState instance. By default,
+RandomState uses the "Mersenne Twister"[1]_ pseudo-random number
+generating algorithm.
Parameters
----------
-state : tuple(str, ndarray of 624 uints, int, int, float)
+state : {tuple(str, ndarray of 624 uints, int, int, float), dict}
The `state` tuple has the following items:
1. the string 'MT19937', specifying the Mersenne Twister algorithm.
@@ -2482,6 +2461,9 @@
4. an integer ``has_gauss``.
5. a float ``cached_gaussian``.
+ If state is a dictionary, it is directly set using the BitGenerators
+ `state` property.
+
Returns
-------
out : None
@@ -2507,7 +2489,7 @@
623-dimensionally equidistributed uniform pseudorandom number
generator," *ACM Trans. on Modeling and Computer Simulation*,
Vol. 8, No. 1, pp. 3-30, Jan. 1998.
+
-
Modify a sequence in-place by shuffling its contents.
@@ -2529,17 +2511,17 @@
>>> arr = np.arange(10)
>>> np.random.shuffle(arr)
>>> arr
-[1 7 5 2 9 4 3 6 0 8]
+[1 7 5 2 9 4 3 6 0 8] # random
Multi-dimensional arrays are only shuffled along the first axis:
>>> arr = np.arange(9).reshape((3, 3))
>>> np.random.shuffle(arr)
>>> arr
-array([[3, 4, 5],
+array([[3, 4, 5], # random
[6, 7, 8],
[0, 1, 2]])
+
-
Draw samples from a standard Cauchy distribution with mode = 0.
@@ -2581,22 +2563,23 @@
----------
.. [1] NIST/SEMATECH e-Handbook of Statistical Methods, "Cauchy
Distribution",
- http://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm
+ https://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm
.. [2] Weisstein, Eric W. "Cauchy Distribution." From MathWorld--A
Wolfram Web Resource.
http://mathworld.wolfram.com/CauchyDistribution.html
.. [3] Wikipedia, "Cauchy distribution"
- http://en.wikipedia.org/wiki/Cauchy_distribution
+ https://en.wikipedia.org/wiki/Cauchy_distribution
Examples
--------
Draw samples and plot the distribution:
+>>> import matplotlib.pyplot as plt
>>> s = np.random.standard_cauchy(1000000)
>>> s = s[(s>-25) & (s<25)] # truncate distribution so it plots well
>>> plt.hist(s, bins=100)
>>> plt.show()
+
-
Draw samples from the standard exponential distribution.
@@ -2620,7 +2603,7 @@
Output a 3x8000 array:
>>> n = np.random.standard_exponential((3, 8000))
+
-
Draw samples from a standard Gamma distribution.
@@ -2630,7 +2613,7 @@
Parameters
----------
shape : float or array_like of floats
- Parameter, should be > 0.
+ Parameter, must be non-negative.
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),
@@ -2666,7 +2649,7 @@
Wolfram Web Resource.
http://mathworld.wolfram.com/GammaDistribution.html
.. [2] Wikipedia, "Gamma distribution",
- http://en.wikipedia.org/wiki/Gamma_distribution
+ https://en.wikipedia.org/wiki/Gamma_distribution
Examples
--------
@@ -2679,13 +2662,13 @@
the probability density function:
>>> import matplotlib.pyplot as plt
->>> import scipy.special as sps
->>> count, bins, ignored = plt.hist(s, 50, normed=True)
->>> y = bins**(shape-1) * ((np.exp(-bins/scale))/ \
+>>> import scipy.special as sps # doctest: +SKIP
+>>> count, bins, ignored = plt.hist(s, 50, density=True)
+>>> y = bins**(shape-1) * ((np.exp(-bins/scale))/ # doctest: +SKIP
... (sps.gamma(shape) * scale**shape))
->>> plt.plot(bins, y, linewidth=2, color='r')
+>>> plt.plot(bins, y, linewidth=2, color='r') # doctest: +SKIP
>>> plt.show()
+
-
Draw samples from a standard Normal distribution (mean=0, stdev=1).
@@ -2699,20 +2682,43 @@
Returns
-------
out : float or ndarray
- Drawn samples.
+ A floating-point array of shape ``size`` of drawn samples, or a
+ single sample if ``size`` was not specified.
+
+Notes
+-----
+For random samples from :math:`N(\mu, \sigma^2)`, use one of::
+
+ mu + sigma * np.random.standard_normal(size=...)
+ np.random.normal(mu, sigma, size=...)
+
+See Also
+--------
+normal :
+ Equivalent function with additional ``loc`` and ``scale`` arguments
+ for setting the mean and standard deviation.
Examples
--------
+>>> np.random.standard_normal()
+2.1923875335537315 #random
+
>>> s = np.random.standard_normal(8000)
>>> s
-array([ 0.6888893 , 0.78096262, -0.89086505, ..., 0.49876311, #random
- -0.38672696, -0.4685006 ]) #random
+array([ 0.6888893 , 0.78096262, -0.89086505, ..., 0.49876311, # random
+ -0.38672696, -0.4685006 ]) # random
>>> s.shape
(8000,)
>>> s = np.random.standard_normal(size=(3, 4, 2))
>>> s.shape
-(3, 4, 2)
+
+(3, 4, 2)
+
+Two-by-four array of samples from :math:`N(3, 6.25)`:
+
+>>> 3 + 2.5 * np.random.standard_normal(size=(2, 4))
+array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random
+ [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random
-
Draw samples from a standard Student's t distribution with `df` degrees
of freedom.
@@ -2723,8 +2729,8 @@
Parameters
----------
-df : int or array_like of ints
- Degrees of freedom, should be > 0.
+df : float or array_like of floats
+ Degrees of freedom, must be > 0.
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),
@@ -2758,12 +2764,12 @@
.. [1] Dalgaard, Peter, "Introductory Statistics With R",
Springer, 2002.
.. [2] Wikipedia, "Student's t-distribution"
- http://en.wikipedia.org/wiki/Student's_t-distribution
+ https://en.wikipedia.org/wiki/Student's_t-distribution
Examples
--------
From Dalgaard page 83 [1]_, suppose the daily energy intake for 11
-women in Kj is:
+women in kilojoules (kJ) is:
>>> intake = np.array([5260., 5470, 5640, 6180, 6390, 6515, 6805, 7515, \
... 7515, 8230, 8770])
@@ -2786,7 +2792,7 @@
>>> t = (np.mean(intake)-7725)/(intake.std(ddof=1)/np.sqrt(len(intake)))
>>> import matplotlib.pyplot as plt
->>> h = plt.hist(s, bins=100, normed=True)
+>>> h = plt.hist(s, bins=100, density=True)
For a one-sided t-test, how far out in the distribution does the t
statistic appear?
@@ -2796,7 +2802,7 @@
So the p-value is about 0.009, which says the null hypothesis has a
probability of about 99% of being true.
+
-
Draw samples from the triangular distribution over the
interval ``[left, right]``.
@@ -2812,9 +2818,9 @@
Lower limit.
mode : float or array_like of floats
The value where the peak of the distribution occurs.
- The value should fulfill the condition ``left <= mode <= right``.
+ The value must fulfill the condition ``left <= mode <= right``.
right : float or array_like of floats
- Upper limit, should be larger than `left`.
+ Upper limit, must be larger than `left`.
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),
@@ -2845,7 +2851,7 @@
References
----------
.. [1] Wikipedia, "Triangular distribution"
- http://en.wikipedia.org/wiki/Triangular_distribution
+ https://en.wikipedia.org/wiki/Triangular_distribution
Examples
--------
@@ -2853,9 +2859,9 @@
>>> import matplotlib.pyplot as plt
>>> h = plt.hist(np.random.triangular(-3, 0, 8, 100000), bins=200,
-... normed=True)
+... density=True)
>>> plt.show()
+
-
Draw samples from a uniform distribution.
@@ -2925,10 +2931,10 @@
probability density function:
>>> import matplotlib.pyplot as plt
->>> count, bins, ignored = plt.hist(s, 15, normed=True)
+>>> count, bins, ignored = plt.hist(s, 15, density=True)
>>> plt.plot(bins, np.ones_like(bins), linewidth=2, color='r')
>>> plt.show()
+
-
Draw samples from a von Mises distribution.
@@ -2996,13 +3002,13 @@
the probability density function:
>>> import matplotlib.pyplot as plt
->>> from scipy.special import i0
->>> plt.hist(s, 50, normed=True)
+>>> from scipy.special import i0 # doctest: +SKIP
+>>> plt.hist(s, 50, density=True)
>>> x = np.linspace(-np.pi, np.pi, num=51)
->>> y = np.exp(kappa*np.cos(x-mu))/(2*np.pi*i0(kappa))
->>> plt.plot(x, y, linewidth=2, color='r')
+>>> y = np.exp(kappa*np.cos(x-mu))/(2*np.pi*i0(kappa)) # doctest: +SKIP
+>>> plt.plot(x, y, linewidth=2, color='r') # doctest: +SKIP
>>> plt.show()
+
-
Draw samples from a Wald, or inverse Gaussian, distribution.
@@ -3018,9 +3024,9 @@
Parameters
----------
mean : float or array_like of floats
- Distribution mean, should be > 0.
+ Distribution mean, must be > 0.
scale : float or array_like of floats
- Scale parameter, should be >= 0.
+ Scale parameter, must be > 0.
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),
@@ -3047,21 +3053,21 @@
References
----------
.. [1] Brighton Webs Ltd., Wald Distribution,
- http://www.brighton-webs.co.uk/distributions/wald.asp
+ https://web.archive.org/web/20090423014010/http://www.brighton-webs.co.uk:80/distributions/wald.asp
.. [2] Chhikara, Raj S., and Folks, J. Leroy, "The Inverse Gaussian
Distribution: Theory : Methodology, and Applications", CRC Press,
1988.
-.. [3] Wikipedia, "Wald distribution"
- http://en.wikipedia.org/wiki/Wald_distribution
+.. [3] Wikipedia, "Inverse Gaussian distribution"
+ https://en.wikipedia.org/wiki/Inverse_Gaussian_distribution
Examples
--------
Draw values from the distribution and plot the histogram:
>>> import matplotlib.pyplot as plt
->>> h = plt.hist(np.random.wald(3, 2, 100000), bins=200, normed=True)
+>>> h = plt.hist(np.random.wald(3, 2, 100000), bins=200, density=True)
>>> plt.show()
+
-
Draw samples from a Weibull distribution.
@@ -3078,7 +3084,7 @@
Parameters
----------
a : float or array_like of floats
- Shape of the distribution. Should be greater than zero.
+ Shape parameter of the distribution. Must be nonnegative.
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),
@@ -3128,7 +3134,7 @@
Wide Applicability", Journal Of Applied Mechanics ASME Paper
1951.
.. [3] Wikipedia, "Weibull distribution",
- http://en.wikipedia.org/wiki/Weibull_distribution
+ https://en.wikipedia.org/wiki/Weibull_distribution
Examples
--------
@@ -3150,7 +3156,7 @@
>>> scale = count.max()/weib(x, 1., 5.).max()
>>> plt.plot(x, weib(x, 1., 5.)*scale)
>>> plt.show()
+
Draw samples from a Zipf distribution.
@@ -3165,7 +3171,7 @@
Parameters
----------
a : float or array_like of floats
- Distribution parameter. Should be greater than 1.
+ Distribution parameter. Must be greater than 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),
@@ -3211,14 +3217,14 @@
the probability density function:
>>> import matplotlib.pyplot as plt
->>> from scipy import special
+>>> from scipy import special # doctest: +SKIP
Truncate s values at 50 so plot is interesting:
->>> count, bins, ignored = plt.hist(s[s<50], 50, normed=True)
+>>> count, bins, ignored = plt.hist(s[s<50], 50, density=True)
>>> x = np.arange(1., 50.)
->>> y = x**(-a) / special.zetac(a)
->>> plt.plot(x, y/max(y), linewidth=2, color='r')
+>>> y = x**(-a) / special.zetac(a) # doctest: +SKIP
+>>> plt.plot(x, y/max(y), linewidth=2, color='r') # doctest: +SKIP
>>> plt.show()