NumPy Pseudorandom Number Generation: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * NumPy Concepts =Overview=")
 
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
* [[Numpy_Concepts#Pseudorandom_Number_Generation|NumPy Concepts]]
* [[Numpy_Concepts#Pseudorandom_Number_Generation|NumPy Concepts]]
=Overview=
=Overview=
The <code>numpy.random</code> module supplements the built-in Python <code>random</code> module with functions for efficiently generating whole arrays of sample values from many kinds of probability distributions.
<syntaxhighlight lang='py'>
np.random.standard_normal(10)
</syntaxhighlight>
<font size=-2>
array([-0.31574999, -0.22620981,  0.78084923, -0.08299547,  0.02537403, -0.39786547,  0.69732466, -1.76220064,  0.26101635, -0.32073839])
</font>
<syntaxhighlight lang='py'>
np.random.standard_normal(size=(5, 3))
</syntaxhighlight>
<font size=-2>
array([[ 6.26367775e-01, -7.97741988e-01,  1.53270456e-01],
        [ 1.66227193e+00, -1.16015757e-03,  9.65301493e-01],
        [-8.90605112e-01,  8.53983237e-01, -4.24828642e-01],
        [-4.60834281e-01, -1.36535277e+00,  1.89016088e+00],
        [-1.25755550e+00,  2.60187554e-01,  5.62396877e-01]])
</font>
<font color=darkkhaki>TODO: https://learning.oreilly.com/library/view/python-for-data/9781098104023/ch04.html#:-:text=These%20random%20numbers%20are%20not%20truly%20random</font>.

Latest revision as of 17:39, 21 May 2024

Internal

Overview

The numpy.random module supplements the built-in Python random module with functions for efficiently generating whole arrays of sample values from many kinds of probability distributions.

np.random.standard_normal(10)

array([-0.31574999, -0.22620981,  0.78084923, -0.08299547,  0.02537403, -0.39786547,  0.69732466, -1.76220064,  0.26101635, -0.32073839])

np.random.standard_normal(size=(5, 3))

array([[ 6.26367775e-01, -7.97741988e-01,  1.53270456e-01],
       [ 1.66227193e+00, -1.16015757e-03,  9.65301493e-01],
       [-8.90605112e-01,  8.53983237e-01, -4.24828642e-01],
       [-4.60834281e-01, -1.36535277e+00,  1.89016088e+00],
       [-1.25755550e+00,  2.60187554e-01,  5.62396877e-01]])

TODO: https://learning.oreilly.com/library/view/python-for-data/9781098104023/ch04.html#:-:text=These%20random%20numbers%20are%20not%20truly%20random.