numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef

Notes

If seed is not a BitGenerator or a Generator , a new BitGenerator is instantiated. This function does not manage a default global instance.

Parameters

seed : {None, int, array_like[ints], SeedSequence, 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 a SeedSequence instance. Additionally, when passed a BitGenerator , it will be wrapped by Generator . If passed a Generator , it will be returned unaltered.

Returns

Generator

The initialized generator object.

Construct a new Generator with the default BitGenerator (PCG64).

Examples

default_rng is the recommended constructor for the random number class Generator . Here are several ways we can construct a random number generator using default_rng and the Generator class.

Here we use default_rng to generate a random float:

>>> import numpy as np
... rng = np.random.default_rng(12345)
... print(rng) Generator(PCG64)
>>> rfloat = rng.random()
... rfloat 0.22733602246716966
>>> type(rfloat)
<class 'float'>

Here we use default_rng to generate 3 random integers between 0 (inclusive) and 10 (exclusive):

>>> import numpy as np
... rng = np.random.default_rng(12345)
... rints = rng.integers(low=0, high=10, size=3)
... rints array([6, 2, 7])
>>> type(rints[0])
<class 'numpy.int64'>

Here we specify a seed so that we have reproducible results:

>>> import numpy as np
... rng = np.random.default_rng(seed=42)
... print(rng) Generator(PCG64)
>>> arr1 = rng.random((3, 3))
... arr1 array([[0.77395605, 0.43887844, 0.85859792], [0.69736803, 0.09417735, 0.97562235], [0.7611397 , 0.78606431, 0.12811363]])

If we exit and restart our Python interpreter, we'll see that we generate the same random numbers again:

>>> import numpy as np
... rng = np.random.default_rng(seed=42)
... arr2 = rng.random((3, 3))
... arr2 array([[0.77395605, 0.43887844, 0.85859792], [0.69736803, 0.09417735, 0.97562235], [0.7611397 , 0.78606431, 0.12811363]])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy

71 Elements
scipy.linalg.blas.find_best_blas_type
scipy.fft._pocketfft.helper.set_workers
scipy.spatial._kdtree.KDTree.count_neighbors
scipy.sparse.linalg._eigen.lobpcg.lobpcg.lobpcg
scipy.linalg._decomp_qr.qr
scipy.linalg._basic.pinv
scipy.optimize._optimize.check_grad
scipy.linalg._decomp_svd.subspace_angles
scipy.signal._signaltools.correlate2d
scipy.signal._signaltools.wiener
scipy.signal._spectral_py.periodogram
scipy.spatial._qhull.ConvexHull
scipy.linalg._decomp_svd.svd
scipy.optimize._zeros_py.newton
scipy.signal._bsplines.qspline1d
scipy.fft._realtransforms.dctn
scipy.fft._realtransforms.idctn
scipy.spatial._kdtree.KDTree.query_ball_tree
scipy.signal._bsplines.cspline1d_eval
scipy.interpolate._polyint.KroghInterpolator
scipy.optimize._basinhopping.basinhopping
scipy.interpolate._bsplines.make_lsq_spline
scipy.interpolate._ndgriddata.NearestNDInterpolator
scipy.spatial._qhull.tsearch
scipy.linalg.lapack.get_lapack_funcs
scipy.fft._helper.next_fast_len
scipy.linalg._expm_frechet.expm_frechet
scipy.interpolate._rbf.Rbf
scipy.signal._signaltools.filtfilt
scipy.signal._signaltools.fftconvolve
scipy.fft._basic.ifft
scipy.signal._spectral_py.lombscargle
scipy.interpolate._fitpack2.LSQUnivariateSpline
scipy.signal._filter_design.freqz
scipy.interpolate._fitpack2.UnivariateSpline
scipy.signal._signaltools.choose_conv_method
scipy.sparse.linalg._eigen._svds.svds
scipy.signal._spectral_py.coherence
scipy.signal._signaltools.sosfiltfilt
scipy.sparse._construct.random
scipy.linalg._decomp_svd.null_space
scipy.signal._spectral_py.stft
scipy.linalg._basic.pinvh
scipy.signal._bsplines.qspline1d_eval
scipy.signal._signaltools.correlation_lags
scipy.signal._signaltools.lfilter
scipy.signal._spectral_py.csd
scipy.interpolate._ndgriddata.griddata
scipy.linalg.blas.get_blas_funcs
scipy.fft._basic.ifftn
scipy.fft._basic.fftn
scipy.spatial._plotutils.voronoi_plot_2d
scipy.fft._realtransforms.idstn
scipy.signal._signaltools.detrend
scipy.signal._bsplines.cspline1d
scipy.spatial._kdtree.KDTree.query_pairs
scipy.signal._signaltools.correlate
scipy.signal._spectral_py.welch
scipy.spatial._plotutils.convex_hull_plot_2d
scipy.fft._realtransforms.dstn
scipy.spatial._plotutils.delaunay_plot_2d
scipy.spatial._kdtree.KDTree.sparse_distance_matrix
scipy.linalg._decomp_qz.qz
scipy.interpolate._fitpack2.InterpolatedUnivariateSpline
scipy.linalg._decomp_qr.rq
scipy.signal._spectral_py.spectrogram
scipy.interpolate.interpnd.LinearNDInterpolator
scipy.interpolate._rbfinterp.RBFInterpolator
scipy.signal._spectral_py.istft
scipy.optimize._minpack_py.curve_fit
scipy.signal._signaltools.oaconvolve

dask

dask.array.routines.corrcoef

numpy

numpy.random._generator.Generator

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : None#None
type: <class 'builtin_function_or_method'>
Commit: