What’s New or Different

Differences from NumPy (1.17+)

Deprecated

Generator is deprecated. You should be using numpy.random.Generator.

  • randomgen’s Generator continues to expose legacy methods random_sample, randint, random_integers, rand, randn, and tomaxint. Note: These should not be used, and their modern replacements are preferred:

    • random_sample, rand` ``random

    • random_integers, randintintegers

    • randnstandard_normal

    • tomaxintintegers with dtype set to int

  • randomgen’s bit generators remain seedable and the convenience function seed` is exposed as part of``Generator. Additionally, the convenience property state is available to get or set the state of the underlying bit generator.

  • numpy.random.Generator.multivariate_hypergeometric() was added after Generator was merged into NumPy and will not be ported over.

  • numpy.random.Generator.shuffle() and numpy.random.Generator.permutation() support axis keyword to operator along an axis other than 0.

  • integers supports the keyword argument use_masked to switch between masked generation of bounded integers and Lemire’s superior method.

Differences from NumPy before 1.17

  • The normal, exponential and gamma generators use 256-step Ziggurat methods which are 2-10 times faster than NumPy’s default implementation in standard_normal, standard_exponential or standard_gamma.

  • The Box-Muller used to produce NumPy’s normals is no longer available.

  • All bit generators functions to produce doubles, uint64s and uint32s via CTypes (ctypes()) and CFFI (cffi()). This allows the bit generators to be used in numba or in other low-level applications

  • The bit generators can be used in downstream projects via Cython.

  • Optional dtype argument that accepts np.float32 or np.float64 to produce either single or double prevision uniform random variables for select core distributions

    • Uniforms (random and rand)

    • Normals (standard_normal and randn)

    • Standard Gammas (standard_gamma)

    • Standard Exponentials (standard_exponential)

  • Optional out argument that allows existing arrays to be filled for select core distributions

    • Uniforms (random)

    • Normals (standard_normal)

    • Standard Gammas (standard_gamma)

    • Standard Exponentials (standard_exponential)

    This allows multithreading to fill large arrays in chunks using suitable PRNGs in parallel.

  • integers supports broadcasting inputs.

  • integers supports drawing from open (default, [low, high)) or closed ([low, high]) intervals using the keyword argument endpoint. Closed intervals are simpler to use when the distribution may include the maximum value of a given integer type.

  • The closed interval is particularly helpful when using arrays since it avoids object-dtype arrays when sampling from the full range.

  • Support for Lemire’s method of generating uniform integers on an arbitrary interval by setting use_masked=True in (integers).

  • multinomial supports multidimensional values of n

  • choice is much faster when sampling small amounts from large arrays

  • choice supports the axis keyword to work with multidimensional arrays.

  • For changes since the previous release, see the Change Log