Return a sample (or samples) from the “standard normal” distribution.
sciphp/numphp>=0.5
SciPhp\NdArray |
float
Random::randn(
array
$shape
)
$shape
This parameter is optional.
This parameter can be an array [1, 2, 3] or a tuple of integers (1, 2, 3).The new SciPhp\NdArray
use SciPhp\NumPhp as np;
$x = np::random()->randn([2, 2]);
// Dimensions may be given as a list
$y = np::random()->randn(2, 2);
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 ]]
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
2.5 * np.random.randn(2, 4) + 3
use SciPhp\NumPhp as np;
// Chain operations
$x = np::random()->randn(4, 2)
->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 ]]