Random::rand

Random values in a given shape.

Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).

sciphp/numphp>=0.5

Description

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

Parameters

$shape
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()->rand([22]);

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

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

The above example will output:

x
[[0.20372898746456  0.98374478145677]
 [0.36084358504081  0.84529060257845]]
y
[[0.26993456867986  0.64427301410785]
 [0.16477621400951  0.63518648344799]]

Example #2: Standard normal usage

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

use SciPhp\NumPhp as np;

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

echo 
"x\n$x";

The above example will output:

x
[[3.2225247864716  3.2668907413105]
 [3.3675023421494  4.1309541511028]
 [3.2353675489944  4.2672627432119]
 [3.8415077537491  4.3796868728845]]

See Also