summaryrefslogtreecommitdiff
path: root/numpy/random/generator.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/random/generator.pyx')
-rw-r--r--numpy/random/generator.pyx51
1 files changed, 27 insertions, 24 deletions
diff --git a/numpy/random/generator.pyx b/numpy/random/generator.pyx
index e68edb98a..7f18392a8 100644
--- a/numpy/random/generator.pyx
+++ b/numpy/random/generator.pyx
@@ -58,19 +58,22 @@ cdef class RandomGenerator:
Examples
--------
- >>> from np.random.randomgen import RandomGenerator
+ >>> from numpy.random import RandomGenerator
>>> rg = RandomGenerator()
>>> rg.standard_normal()
+ -0.203 # random
Using a specific generator
- >>> from np.random.randomgen import MT19937
+ >>> from numpy.random import MT19937
>>> rg = RandomGenerator(MT19937())
The generator is also directly available from basic RNGs
>>> rg = MT19937().generator
>>> rg.standard_normal()
+ -0.203 # random
+
"""
cdef public object brng
cdef brng_t *_brng
@@ -92,7 +95,8 @@ cdef class RandomGenerator:
self.lock = brng.lock
def __dealloc__(self):
- free(self._binomial)
+ if self._binomial:
+ free(self._binomial)
def __repr__(self):
return self.__str__() + ' at 0x{:X}'.format(id(self))
@@ -351,14 +355,12 @@ cdef class RandomGenerator:
Examples
--------
- >>> rg = np.random.randomgen.RandomGenerator() # need a RandomGenerator object
+ >>> rg = np.random.RandomGenerator() # need a RandomGenerator object
>>> rg.tomaxint((2,2,2))
array([[[1170048599, 1600360186], # random
[ 739731006, 1947757578]],
[[1871712945, 752307660],
[1601631370, 1479324245]]])
- >>> np.iinfo(np.int).max
- 2147483647
>>> rg.tomaxint((2,2,2)) < np.iinfo(np.int).max
array([[[ True, True],
[ True, True]],
@@ -1275,11 +1277,11 @@ cdef class RandomGenerator:
the probability density function:
>>> import matplotlib.pyplot as plt
- >>> import scipy.special as sps
+ >>> import scipy.special as sps # doctest: +SKIP
>>> count, bins, ignored = plt.hist(s, 50, density=True)
- >>> y = bins**(shape-1) * ((np.exp(-bins/scale))/ \\
+ >>> 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()
"""
@@ -1363,11 +1365,11 @@ cdef class RandomGenerator:
the probability density function:
>>> import matplotlib.pyplot as plt
- >>> import scipy.special as sps
+ >>> import scipy.special as sps # doctest: +SKIP
>>> count, bins, ignored = plt.hist(s, 50, density=True)
- >>> y = bins**(shape-1)*(np.exp(-bins/scale) /
+ >>> 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()
"""
@@ -1917,11 +1919,11 @@ cdef class RandomGenerator:
the probability density function:
>>> import matplotlib.pyplot as plt
- >>> from scipy.special import i0
+ >>> 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()
"""
@@ -2199,25 +2201,25 @@ cdef class RandomGenerator:
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, density=True)
- >>> plt.plot(xx,powpdf,'r-')
+ >>> plt.plot(xx,powpdf,'r-') # doctest: +SKIP
>>> plt.title('np.random.power(5)')
>>> plt.figure()
>>> plt.hist(1./(1.+rvsp), bins=50, density=True)
- >>> plt.plot(xx,powpdf,'r-')
+ >>> 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, density=True)
- >>> plt.plot(xx,powpdf,'r-')
+ >>> plt.plot(xx,powpdf,'r-') # doctest: +SKIP
>>> plt.title('inverse of stats.pareto(5)')
"""
@@ -3208,14 +3210,15 @@ cdef class RandomGenerator:
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, density=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()
"""