Random::randn

Return a sample (or samples) from the “standard normal” distribution.

sciphp/numphp>=0.5

Description

SciPhp\NdArray | float Random::randn( array $shape )

Parameters

$shape

This parameter is optional.

This parameter can be an array [1, 2, 3] or a tuple of integers (1, 2, 3).

Return Values

The new SciPhp\NdArray

Examples

Example #1: A 2x2 matrix with random samples

use SciPhp\NumPhp as np;

$x np::random()->randn([22]);

// Dimensions may be given as a list
$y np::random()->randn(22);

echo 
"x\n$x""y\n$y";

The above example will output:

x
[[-1.0314668501755    -0.20875053683428 ]
 [-0.18028808349697    0.70316066128862 ]]
y
[[-2.5371584413573    -0.90673521294318 ]
 [ 0.072800653810671  -1.6912313186412  ]]

Example #2: Single float value

If no argument is given, a single float is returned.

use SciPhp\NumPhp as np;

$x np::random()->randn();

echo 
"$x";

The above example will output:

2.0450638649566

Example #3: Standard normal usage

2.5 * np.random.randn(2, 4) + 3

use SciPhp\NumPhp as np;

// Chain operations
$x np::random()->randn(42)
                 ->
dot(2.5)
                 ->
add(3);

echo 
"x\n$x";

The above example will output:

x
[[ 0.2871680360833    4.1630175467801 ]
 [ 1.2614584053774    5.6605538900953 ]
 [ 3.2456139405051   -2.1206885652537 ]
 [ 2.1875522275875    3.8683560179717 ]]

See Also