__init__.py 7.3 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. PCG64DXSM
  18. Philox
  19. SFC64
  20. ============================================= ===
  21. ============================================= ===
  22. Getting entropy to initialize a BitGenerator
  23. --------------------------------------------- ---
  24. SeedSequence
  25. ============================================= ===
  26. Legacy
  27. ------
  28. For backwards compatibility with previous versions of numpy before 1.17, the
  29. various aliases to the global `RandomState` methods are left alone and do not
  30. use the new `Generator` API.
  31. ==================== =========================================================
  32. Utility functions
  33. -------------------- ---------------------------------------------------------
  34. random Uniformly distributed floats over ``[0, 1)``
  35. bytes Uniformly distributed random bytes.
  36. permutation Randomly permute a sequence / generate a random sequence.
  37. shuffle Randomly permute a sequence in place.
  38. choice Random sample from 1-D array.
  39. ==================== =========================================================
  40. ==================== =========================================================
  41. Compatibility
  42. functions - removed
  43. in the new API
  44. -------------------- ---------------------------------------------------------
  45. rand Uniformly distributed values.
  46. randn Normally distributed values.
  47. ranf Uniformly distributed floating point numbers.
  48. random_integers Uniformly distributed integers in a given range.
  49. (deprecated, use ``integers(..., closed=True)`` instead)
  50. random_sample Alias for `random_sample`
  51. randint Uniformly distributed integers in a given range
  52. seed Seed the legacy random number generator.
  53. ==================== =========================================================
  54. ==================== =========================================================
  55. Univariate
  56. distributions
  57. -------------------- ---------------------------------------------------------
  58. beta Beta distribution over ``[0, 1]``.
  59. binomial Binomial distribution.
  60. chisquare :math:`\\chi^2` distribution.
  61. exponential Exponential distribution.
  62. f F (Fisher-Snedecor) distribution.
  63. gamma Gamma distribution.
  64. geometric Geometric distribution.
  65. gumbel Gumbel distribution.
  66. hypergeometric Hypergeometric distribution.
  67. laplace Laplace distribution.
  68. logistic Logistic distribution.
  69. lognormal Log-normal distribution.
  70. logseries Logarithmic series distribution.
  71. negative_binomial Negative binomial distribution.
  72. noncentral_chisquare Non-central chi-square distribution.
  73. noncentral_f Non-central F distribution.
  74. normal Normal / Gaussian distribution.
  75. pareto Pareto distribution.
  76. poisson Poisson distribution.
  77. power Power distribution.
  78. rayleigh Rayleigh distribution.
  79. triangular Triangular distribution.
  80. uniform Uniform distribution.
  81. vonmises Von Mises circular distribution.
  82. wald Wald (inverse Gaussian) distribution.
  83. weibull Weibull distribution.
  84. zipf Zipf's distribution over ranked data.
  85. ==================== =========================================================
  86. ==================== ==========================================================
  87. Multivariate
  88. distributions
  89. -------------------- ----------------------------------------------------------
  90. dirichlet Multivariate generalization of Beta distribution.
  91. multinomial Multivariate generalization of the binomial distribution.
  92. multivariate_normal Multivariate generalization of the normal distribution.
  93. ==================== ==========================================================
  94. ==================== =========================================================
  95. Standard
  96. distributions
  97. -------------------- ---------------------------------------------------------
  98. standard_cauchy Standard Cauchy-Lorentz distribution.
  99. standard_exponential Standard exponential distribution.
  100. standard_gamma Standard Gamma distribution.
  101. standard_normal Standard normal distribution.
  102. standard_t Standard Student's t-distribution.
  103. ==================== =========================================================
  104. ==================== =========================================================
  105. Internal functions
  106. -------------------- ---------------------------------------------------------
  107. get_state Get tuple representing internal state of generator.
  108. set_state Set state of generator.
  109. ==================== =========================================================
  110. """
  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, PCG64DXSM
  171. from ._philox import Philox
  172. from ._sfc64 import SFC64
  173. from .mtrand import *
  174. __all__ += ['Generator', 'RandomState', 'SeedSequence', 'MT19937',
  175. 'Philox', 'PCG64', 'PCG64DXSM', 'SFC64', 'default_rng',
  176. 'BitGenerator']
  177. def __RandomState_ctor():
  178. """Return a RandomState instance.
  179. This function exists solely to assist (un)pickling.
  180. Note that the state of the RandomState returned here is irrelevant, as this
  181. function's entire purpose is to return a newly allocated RandomState whose
  182. state pickle can set. Consequently the RandomState returned by this function
  183. is a freshly allocated copy with a seed=0.
  184. See https://github.com/numpy/numpy/issues/4763 for a detailed discussion
  185. """
  186. return RandomState(seed=0)
  187. from numpy._pytesttester import PytestTester
  188. test = PytestTester(__name__)
  189. del PytestTester