NdArray::power

Array elements raised to powers, element-wise.

Description

SciPhp\NdArray NdArray::power( float|int $exponent )

Parameters

$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 $m->power(2);

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