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
SciPhp\NdArray
Random::randn(
array
$shape
)
$shape
The new SciPhp\NdArray
use SciPhp\NumPhp as np;
$x = np::random()->rand([2, 2]);
// Dimensions may be given as a list
$y = np::random()->rand(2, 2);
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]]
2.5 * np.random.rand(2, 4) + 3
use SciPhp\NumPhp as np;
// Chain operations
$x = np::random()->rand(4, 2)
->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]]