NumPhp::power

Array elements raised to powers, element-wise.

Description

SciPhp\NdArray NumPhp::power( array|NdArray $m , float|int $exponent )

Parameters

$m
An array [1, 2, 3] or a NdArray.
$exponent
A float or an integer. The exponent.

Return Values

SciPhp\NdArray

Examples

Example #1: Powers a square matrix

use SciPhp\NumPhp as np;

$m np::linspace(199)->reshape(33);

$p np::power($m2);

echo 
"m\n$m""s=m.\n$s";

The above example will output:

m
[[1  2  3]
 [4  5  6]
 [7  8  9]]
p=m ** 2
[[1   4   9 ]
 [16  25  36]
 [49  64  81]]

See Also