__init__.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. """
  2. ========================
  3. Random Number Generation
  4. ========================
  5. Use ``default_rng()`` to create a `Generator` and call its methods.
  6. =============== =========================================================
  7. Generator
  8. --------------- ---------------------------------------------------------
  9. Generator Class implementing all of the random number distributions
  10. default_rng Default constructor for ``Generator``
  11. =============== =========================================================
  12. ============================================= ===
  13. BitGenerator Streams that work with Generator
  14. --------------------------------------------- ---
  15. MT19937
  16. PCG64
  17. Philox
  18. SFC64
  19. ============================================= ===
  20. ============================================= ===
  21. Getting entropy to initialize a BitGenerator
  22. --------------------------------------------- ---
  23. SeedSequence
  24. ============================================= ===
  25. Legacy
  26. ------
  27. For backwards compatibility with previous versions of numpy before 1.17, the
  28. various aliases to the global `RandomState` methods are left alone and do not
  29. use the new `Generator` API.
  30. ==================== =========================================================
  31. Utility functions
  32. -------------------- ---------------------------------------------------------
  33. random Uniformly distributed floats over ``[0, 1)``
  34. bytes Uniformly distributed random bytes.
  35. permutation Randomly permute a sequence / generate a random sequence.
  36. shuffle Randomly permute a sequence in place.
  37. choice Random sample from 1-D array.
  38. ==================== =========================================================
  39. ==================== =========================================================
  40. Compatibility
  41. functions - removed
  42. in the new API
  43. -------------------- ---------------------------------------------------------
  44. rand Uniformly distributed values.
  45. randn Normally distributed values.
  46. ranf Uniformly distributed floating point numbers.
  47. random_integers Uniformly distributed integers in a given range.
  48. (deprecated, use ``integers(..., closed=True)`` instead)
  49. random_sample Alias for `random_sample`
  50. randint Uniformly distributed integers in a given range
  51. seed Seed the legacy random number generator.
  52. ==================== =========================================================
  53. ==================== =========================================================
  54. Univariate
  55. distributions
  56. -------------------- ---------------------------------------------------------
  57. beta Beta distribution over ``[0, 1]``.
  58. binomial Binomial distribution.
  59. chisquare :math:`\\chi^2` distribution.
  60. exponential Exponential distribution.
  61. f F (Fisher-Snedecor) distribution.
  62. gamma Gamma distribution.
  63. geometric Geometric distribution.
  64. gumbel Gumbel distribution.
  65. hypergeometric Hypergeometric distribution.
  66. laplace Laplace distribution.
  67. logistic Logistic distribution.
  68. lognormal Log-normal distribution.
  69. logseries Logarithmic series distribution.
  70. negative_binomial Negative binomial distribution.
  71. noncentral_chisquare Non-central chi-square distribution.
  72. noncentral_f Non-central F distribution.
  73. normal Normal / Gaussian distribution.
  74. pareto Pareto distribution.
  75. poisson Poisson distribution.
  76. power Power distribution.
  77. rayleigh Rayleigh distribution.
  78. triangular Triangular distribution.
  79. uniform Uniform distribution.
  80. vonmises Von Mises circular distribution.
  81. wald Wald (inverse Gaussian) distribution.
  82. weibull Weibull distribution.
  83. zipf Zipf's distribution over ranked data.
  84. ==================== =========================================================
  85. ==================== ==========================================================
  86. Multivariate
  87. distributions
  88. -------------------- ----------------------------------------------------------
  89. dirichlet Multivariate generalization of Beta distribution.
  90. multinomial Multivariate generalization of the binomial distribution.
  91. multivariate_normal Multivariate generalization of the normal distribution.
  92. ==================== ==========================================================
  93. ==================== =========================================================
  94. Standard
  95. distributions
  96. -------------------- ---------------------------------------------------------
  97. standard_cauchy Standard Cauchy-Lorentz distribution.
  98. standard_exponential Standard exponential distribution.
  99. standard_gamma Standard Gamma distribution.
  100. standard_normal Standard normal distribution.
  101. standard_t Standard Student's t-distribution.
  102. ==================== =========================================================
  103. ==================== =========================================================
  104. Internal functions
  105. -------------------- ---------------------------------------------------------
  106. get_state Get tuple representing internal state of generator.
  107. set_state Set state of generator.
  108. ==================== =========================================================
  109. """
  110. from __future__ import division, absolute_import, print_function
  111. __all__ = [
  112. 'beta',
  113. 'binomial',
  114. 'bytes',
  115. 'chisquare',
  116. 'choice',
  117. 'dirichlet',
  118. 'exponential',
  119. 'f',
  120. 'gamma',
  121. 'geometric',
  122. 'get_state',
  123. 'gumbel',
  124. 'hypergeometric',
  125. 'laplace',
  126. 'logistic',
  127. 'lognormal',
  128. 'logseries',
  129. 'multinomial',
  130. 'multivariate_normal',
  131. 'negative_binomial',
  132. 'noncentral_chisquare',
  133. 'noncentral_f',
  134. 'normal',
  135. 'pareto',
  136. 'permutation',
  137. 'poisson',
  138. 'power',
  139. 'rand',
  140. 'randint',
  141. 'randn',
  142. 'random',
  143. 'random_integers',
  144. 'random_sample',
  145. 'ranf',
  146. 'rayleigh',
  147. 'sample',
  148. 'seed',
  149. 'set_state',
  150. 'shuffle',
  151. 'standard_cauchy',
  152. 'standard_exponential',
  153. 'standard_gamma',
  154. 'standard_normal',
  155. 'standard_t',
  156. 'triangular',
  157. 'uniform',
  158. 'vonmises',
  159. 'wald',
  160. 'weibull',
  161. 'zipf',
  162. ]
  163. # add these for module-freeze analysis (like PyInstaller)
  164. from . import _pickle
  165. from . import _common
  166. from . import _bounded_integers
  167. from ._generator import Generator, default_rng
  168. from ._bit_generator import SeedSequence, BitGenerator
  169. from ._mt19937 import MT19937
  170. from ._pcg64 import PCG64
  171. from ._philox import Philox
  172. from ._sfc64 import SFC64
  173. from .mtrand import *
  174. __all__ += ['Generator', 'RandomState', 'SeedSequence', 'MT19937',
  175. 'Philox', 'PCG64', 'SFC64', 'default_rng', 'BitGenerator']
  176. def __RandomState_ctor():
  177. """Return a RandomState instance.
  178. This function exists solely to assist (un)pickling.
  179. Note that the state of the RandomState returned here is irrelevant, as this
  180. function's entire purpose is to return a newly allocated RandomState whose
  181. state pickle can set. Consequently the RandomState returned by this function
  182. is a freshly allocated copy with a seed=0.
  183. See https://github.com/numpy/numpy/issues/4763 for a detailed discussion
  184. """
  185. return RandomState(seed=0)
  186. from numpy._pytesttester import PytestTester
  187. test = PytestTester(__name__)
  188. del PytestTester