NdArray::log

Return the natural logarithm, element-wise.

Description

SciPhp\NdArray NdArray::log( [ int $base ])

Parameters

$base
A positive integer.

Return Values

A SciPhp\NdArray

Examples

Example #1: Get log of a vector

use SciPhp\NumPhp as np;

$m np::ar([1M_EM_E ** 2M_E ** 3])->log();

echo 
"m\n$m";

The above example will output:

m
[0  1  2  3]

Example #2: Get log of a matrix

use SciPhp\NumPhp as np;

$m np::ar([1M_EM_E ** 2])->vander();

$r $m->log();

echo 
"m\n$m""r\n$r";

The above example will output:

m
[[1                1                1              ]
 [7.3890560989306  2.718281828459   1              ]
 [54.598150033144  7.3890560989306  1              ]]
r
[[0  0  0]
 [2  1  0]
 [4  2  0]]

Example #3: Get logarithms in base 100

use SciPhp\NumPhp as np;

$m np::ar([1100100 ** 2])->vander();

$r $m->log(100);

echo 
"m\n$m""r\n$r";

The above example will output:

m
[[1          1          1        ]
 [10000      100        1        ]
 [100000000  10000      1        ]]
r
[[0  0  0]
 [2  1  0]
 [4  2  0]]

See Also