NdArray::divide

Divide two matrices, element-wise.

Description

SciPhp\NdArray NdArray::divide( array|NdArray $n )

Parameters

$n
An array [1, 2, 3] or a NdArray.

Return Values

The new SciPhp\NdArray

Examples

Example #1: Divide all elements by lambda

use SciPhp\NumPhp as np;

$m np::vander([123]);

$d $m->divide(2);

echo 
"m\n$m""d=m/2\n$d";

The above example will output:

m
[[1  1  1]
 [4  2  1]
 [9  3  1]]
d=m/2
[[0.5  0.5  0.5]
 [2    1    0.5]
 [4.5  1.5  0.5]]

Example #2: Divide two square matrices

use SciPhp\NumPhp as np;

$m np::arange(0182)->reshape(33);
$n np::vander([124]);

$d np::divide($m$n);

echo 
"m\n$m""n\n$n""d=m/n\n$d";

The above example will output:

m
[[0   2   4 ]
 [6   8   10]
 [12  14  16]]
n
[[1   1   1 ]
 [4   2   1 ]
 [16  4   1 ]]
d=m/n
[[0     2     4   ]
 [1.5   4     10  ]
 [0.75  3.5   16  ]]

See Also