final class NumPhp extends Decorator (View source)

Entry point for np calls.

Traits

Methods

static 
reciprocal(NdArray|array|float|int $m)

Return the reciprocal of the argument, element-wise.

static 
subtract(NdArray|array|float|int $m, NdArray|array|float|int $n)

Subtract a matrix from matrix

static NdArray|int|float
add(NdArray|array|int|float $m, NdArray|array|int|float $n)

Add two array_like

static NdArray|float|int
divide(NdArray|array|float|int $m, NdArray|array|float|int $n)

Divide two arrays, element-wise

static NdArray|float|int
multiply(NdArray|array|float|int $m, NdArray|array|float|int $n)

Multiply two arrays, element-wise

static NdArray|float|int
dot(NdArray|array|float|int $m, NdArray|array|float|int $n)

Dot product of two arrays

static callable
rowDot(NdArray $m, NdArray $n)

Browse p rows

static callable
colDot($row_m, NdArray $m, NdArray $n)

Browse p cols and sum products

static int|float|array
trace(NdArray|array $m, int $k = 0)

Sum along diagonals

static NdArray
identity(int $n)

Construct an identity array

static NdArray
eye(int $rows, int $cols = 0, int $k = 0)

Construct a diagonal array

static NdArray
diag(array|NdArray $m, int $k = 0)

Extract a diagonal or construct a diagonal array

static NdArray
diagonal(NdArray|array $m, int $k = 0)

Extract a diagonal

static NdArray
diagflat(mixed $m, int $k = 0)

Create a two-dimensional array with the flattened input as a diagonal.

static NdArray
fromDiagonal(array $diagonal, int $k)

Construct a diagonal array

static callable
itemFromDiagonal(int $col, array $diagonal, int $k, int $line = 1)

Fill a line among diagonal, offset and indexes

static NdArray|int|float
exp(NdArray|array|int|float $m)

Calculate the exponential of all elements in the input array.

static NdArray|int|float
expm1(NdArray|array|int|float $m)

Calculate exp(x) - 1 for all elements in the array.

static NdArray|int|float
exp2(NdArray|array|int|float $m)

Calculate 2**p for all p in the input array.

static 
power(float|int|array|NdArray $matrix, float|int $exponent)

Matrix elements raised to powers.

static float|int|NdArray
square(float|int|array|NdArray $matrix)

The element-wise square of the input.

static NdArray
sqrt($matrix)

The non-negative square-root of an array, element-wise.

static LinAlg
linalg()

Loads Linear Algebra extension

static Random
random()

Loads Random generator extension

static NdArray
loadtxt(string $file, array $options = [])

Load data from a text file.

static NdArray|bool
signbit(NdArray|array|int|float $m)

Returns element-wise true where signbit is set (less than zero).

static NdArray|int|float
copysign(NdArray|array|int|float $m, NdArray|array|int|float $n)

Change the sign of m-element to that of n-element, element-wise.

static NdArray|int|float
log(NdArray|array|int|float $m, int|float $base = M_E)

Natural logarithm, element-wise.

static NdArray|int|float
log10(NdArray|array|int|float $m)

Base 10 logarithm, element-wise.

static NdArray|int|float
log2(NdArray|array|int|float $m)

Base 2 logarithm, element-wise.

static NdArray|int|float
cos(NdArray|array|int|float $m)

Cosine element-wise.

static NdArray|int|float
sin(NdArray|array|int|float $m)

Trigonometric sine, element-wise.

static NdArray|int|float
tan(NdArray|array|int|float $m)

Compute tangent element-wise.

static bool
is_square(NdArray|array $m)

Is given matrix a square matrix ?

static NdArray|int|float
negative(NdArray|array|int|float $m)

Numerical negative, element-wise.

static NdArray
transpose(array|NdArray $m)

Permute the dimensions of an array.

static NdArray
zeros()

Creates a NdArray with zero as default value

static NdArray
ones()

Creates a NdArray with one as default value

static NdArray
nulls()

Creates a NdArray with null as default value 'empty' can not be used in PHP

static NdArray
full(array $shape, mixed $value)

Creates a NdArray with a default value

static mixed|array
createArray(array $params, mixed $value)

Construct a n-dim array with a default value

static NdArray
nulls_like(array|NdArray $matrix)

Construct a new array of nulls with the same shape and type as a given array.

static NdArray
zeros_like(array|NdArray $matrix)

Construct a new array of zeros with the same shape and type as a given array.

static NdArray
ones_like(array|NdArray $matrix)

Construct a new array of ones with the same shape and type as a given array.

static NdArray
full_like(array|NdArray $matrix, $value = null)

Construct a new array with the same shape and type as a given array, filled with a given value

static NdArray
broadcast_to(array|NdArray $matrix, array $shape)

Broadcast an array to a new shape.

static int|float|NdArray
sum(NdArray|array|int|float $m, int|null $axis = null, bool $keepdims = false)

Sum all elements.

static int|float|array
trapz(NdArray|array $m)

Integrate along the given axis using the composite trapezoidal rule.

static NdArray
arange(int|float $start, int|float $end = null, int|float $step = 1)

Creates a NdArray with a range of values

static 
linspace($start, $end, int $num = 50, bool $endpoint = true, bool $retstep = false)

No description

static NdArray
logspace(int|float $start, int|float $end, int $num = 50, bool $endpoint = true, float $base = 10)

Creates a NdArray with a range of values

static NdArray
triu(NdArray|array $m, int $k = 0)

Upper triangle of an array

static callable
itemTriu(int $col, int $k, int $count, int $line = 1)

Fill zeros from first item to a position

static NdArray
tril(NdArray|array $m, int $k = 0)

Lower triangle of an array

static callable
itemTril(int $col, int $k, int $count, int $line = 1)

Fill zeros from a position to the end of the array

static NdArray
tri(int $rows, int $cols = null, int $k = 0)

Construct an array with ones at and below the given diagonal and zeros elsewhere

static callable
itemTri(int $col, int $k, int $maxCols, int|null $line = 1)

Return a closure that fill a line item with ones

static NdArray
vander(NdArray|array $matrix, int $num = null)

Generate a Vandermonde matrix.

static callable
itemVander(int $num)

Apply decreasing power on each row values

static NdArray
ar(array $data, string|null $identifier = null)

Construct a n-dimensional array

static array
parseArgs(array $args)

Parse args as a tuple or an array

static void
transform(array|NdArray $m, bool $required = false)

Transform a PHP array in a NdArray

static bool
allNumeric()

Check that all values are numeric

Details

final static reciprocal(NdArray|array|float|int $m)

Return the reciprocal of the argument, element-wise.

Parameters

NdArray|array|float|int $m

final static subtract(NdArray|array|float|int $m, NdArray|array|float|int $n)

Subtract a matrix from matrix

Parameters

NdArray|array|float|int $m
NdArray|array|float|int $n

final static NdArray|int|float add(NdArray|array|int|float $m, NdArray|array|int|float $n)

Add two array_like

Parameters

NdArray|array|int|float $m
NdArray|array|int|float $n

Return Value

NdArray|int|float

final static NdArray|float|int divide(NdArray|array|float|int $m, NdArray|array|float|int $n)

Divide two arrays, element-wise

Parameters

NdArray|array|float|int $m A 2-dim array.
NdArray|array|float|int $n A 2-dim array.

Return Value

NdArray|float|int

Exceptions

InvalidArgumentException

final static NdArray|float|int multiply(NdArray|array|float|int $m, NdArray|array|float|int $n)

Multiply two arrays, element-wise

Parameters

NdArray|array|float|int $m A 2-dim array.
NdArray|array|float|int $n A 2-dim array.

Return Value

NdArray|float|int

Exceptions

InvalidArgumentException

final static NdArray|float|int dot(NdArray|array|float|int $m, NdArray|array|float|int $n)

Dot product of two arrays

Parameters

NdArray|array|float|int $m A 2-dim array.
NdArray|array|float|int $n A 2-dim array.

Return Value

NdArray|float|int

Exceptions

InvalidArgumentException

final static protected callable rowDot(NdArray $m, NdArray $n)

Browse p rows

Parameters

NdArray $m
NdArray $n

Return Value

callable

final static protected callable colDot($row_m, NdArray $m, NdArray $n)

Browse p cols and sum products

Parameters

$row_m
NdArray $m
NdArray $n

Return Value

callable

final static int|float|array trace(NdArray|array $m, int $k = 0)

Sum along diagonals

Parameters

NdArray|array $m
int $k offset

Return Value

int|float|array

Exceptions

InvalidArgumentException

final static NdArray identity(int $n)

Construct an identity array

Parameters

int $n

Return Value

NdArray

Exceptions

InvalidArgumentException

final static NdArray eye(int $rows, int $cols = 0, int $k = 0)

Construct a diagonal array

Parameters

int $rows Number of rows
int $cols Number of columns
int $k Offset

Return Value

NdArray

final static NdArray diag(array|NdArray $m, int $k = 0)

Extract a diagonal or construct a diagonal array

Parameters

array|NdArray $m
int $k Diagonal

Return Value

NdArray

Exceptions

InvalidArgumentException

final static NdArray diagonal(NdArray|array $m, int $k = 0)

Extract a diagonal

Parameters

NdArray|array $m
int $k Offset

Return Value

NdArray

final static NdArray diagflat(mixed $m, int $k = 0)

Create a two-dimensional array with the flattened input as a diagonal.

Parameters

mixed $m An array to flatten
int $k

Return Value

NdArray

final static protected NdArray fromDiagonal(array $diagonal, int $k)

Construct a diagonal array

Parameters

array $diagonal
int $k

Return Value

NdArray

final static protected callable itemFromDiagonal(int $col, array $diagonal, int $k, int $line = 1)

Fill a line among diagonal, offset and indexes

Parameters

int $col Diagonal column index
array $diagonal
int $k Offset
int $line

Return Value

callable

final static NdArray|int|float exp(NdArray|array|int|float $m)

Calculate the exponential of all elements in the input array.

Parameters

NdArray|array|int|float $m

Return Value

NdArray|int|float

final static NdArray|int|float expm1(NdArray|array|int|float $m)

Calculate exp(x) - 1 for all elements in the array.

Parameters

NdArray|array|int|float $m

Return Value

NdArray|int|float

final static NdArray|int|float exp2(NdArray|array|int|float $m)

Calculate 2**p for all p in the input array.

Parameters

NdArray|array|int|float $m

Return Value

NdArray|int|float

final static power(float|int|array|NdArray $matrix, float|int $exponent)

Matrix elements raised to powers.

Parameters

float|int|array|NdArray $matrix
float|int $exponent

final static float|int|NdArray square(float|int|array|NdArray $matrix)

The element-wise square of the input.

Parameters

float|int|array|NdArray $matrix

Return Value

float|int|NdArray

final static NdArray sqrt($matrix)

The non-negative square-root of an array, element-wise.

Parameters

$matrix

Return Value

NdArray

final static LinAlg linalg()

Loads Linear Algebra extension

Return Value

LinAlg

final static Random random()

Loads Random generator extension

Return Value

Random

final static NdArray loadtxt(string $file, array $options = [])

Load data from a text file.

Parameters

string $file
array $options default is [ 'headers' => false, 'delimiter' => ';' ]

Return Value

NdArray

final static NdArray|bool signbit(NdArray|array|int|float $m)

Returns element-wise true where signbit is set (less than zero).

Parameters

NdArray|array|int|float $m

Return Value

NdArray|bool

final static NdArray|int|float copysign(NdArray|array|int|float $m, NdArray|array|int|float $n)

Change the sign of m-element to that of n-element, element-wise.

Parameters

NdArray|array|int|float $m
NdArray|array|int|float $n

Return Value

NdArray|int|float

final static NdArray|int|float log(NdArray|array|int|float $m, int|float $base = M_E)

Natural logarithm, element-wise.

Parameters

NdArray|array|int|float $m
int|float $base

Return Value

NdArray|int|float

final static NdArray|int|float log10(NdArray|array|int|float $m)

Base 10 logarithm, element-wise.

Parameters

NdArray|array|int|float $m

Return Value

NdArray|int|float

final static NdArray|int|float log2(NdArray|array|int|float $m)

Base 2 logarithm, element-wise.

Parameters

NdArray|array|int|float $m

Return Value

NdArray|int|float

final static NdArray|int|float cos(NdArray|array|int|float $m)

Cosine element-wise.

Parameters

NdArray|array|int|float $m

Return Value

NdArray|int|float

final static NdArray|int|float sin(NdArray|array|int|float $m)

Trigonometric sine, element-wise.

Parameters

NdArray|array|int|float $m

Return Value

NdArray|int|float

final static NdArray|int|float tan(NdArray|array|int|float $m)

Compute tangent element-wise.

Equivalent to np::sin(x)->divide(np::cos(x)) element-wise.

Parameters

NdArray|array|int|float $m

Return Value

NdArray|int|float

final static bool is_square(NdArray|array $m)

Is given matrix a square matrix ?

Parameters

NdArray|array $m

Return Value

bool

final static NdArray|int|float negative(NdArray|array|int|float $m)

Numerical negative, element-wise.

Parameters

NdArray|array|int|float $m

Return Value

NdArray|int|float

final static NdArray transpose(array|NdArray $m)

Permute the dimensions of an array.

Parameters

array|NdArray $m

Return Value

NdArray

Exceptions

InvalidArgumentException

final static NdArray zeros()

Creates a NdArray with zero as default value

Return Value

NdArray

final static NdArray ones()

Creates a NdArray with one as default value

Return Value

NdArray

final static NdArray nulls()

Creates a NdArray with null as default value 'empty' can not be used in PHP

Return Value

NdArray

final static NdArray full(array $shape, mixed $value)

Creates a NdArray with a default value

Parameters

array $shape
mixed $value

Return Value

NdArray

final static protected mixed|array createArray(array $params, mixed $value)

Construct a n-dim array with a default value

Parameters

array $params
mixed $value

Return Value

mixed|array

final static NdArray nulls_like(array|NdArray $matrix)

Construct a new array of nulls with the same shape and type as a given array.

Parameters

array|NdArray $matrix

Return Value

NdArray

final static NdArray zeros_like(array|NdArray $matrix)

Construct a new array of zeros with the same shape and type as a given array.

Parameters

array|NdArray $matrix

Return Value

NdArray

final static NdArray ones_like(array|NdArray $matrix)

Construct a new array of ones with the same shape and type as a given array.

Parameters

array|NdArray $matrix

Return Value

NdArray

final static NdArray full_like(array|NdArray $matrix, $value = null)

Construct a new array with the same shape and type as a given array, filled with a given value

Parameters

array|NdArray $matrix
$value

Return Value

NdArray

final static NdArray broadcast_to(array|NdArray $matrix, array $shape)

Broadcast an array to a new shape.

Parameters

array|NdArray $matrix
array $shape

Return Value

NdArray

final static int|float|NdArray sum(NdArray|array|int|float $m, int|null $axis = null, bool $keepdims = false)

Sum all elements.

Parameters

NdArray|array|int|float $m
int|null $axis
bool $keepdims

Return Value

int|float|NdArray

final static int|float|array trapz(NdArray|array $m)

Integrate along the given axis using the composite trapezoidal rule.

Parameters

NdArray|array $m

Return Value

int|float|array

final static NdArray arange(int|float $start, int|float $end = null, int|float $step = 1)

Creates a NdArray with a range of values

Parameters

int|float $start
int|float $end
int|float $step

Return Value

NdArray

final static linspace($start, $end, int $num = 50, bool $endpoint = true, bool $retstep = false)

Parameters

$start
$end
int $num
bool $endpoint
bool $retstep

final static NdArray logspace(int|float $start, int|float $end, int $num = 50, bool $endpoint = true, float $base = 10)

Creates a NdArray with a range of values

Parameters

int|float $start
int|float $end
int $num
bool $endpoint
float $base

Return Value

NdArray

final static NdArray triu(NdArray|array $m, int $k = 0)

Upper triangle of an array

Parameters

NdArray|array $m
int $k Offset

Return Value

NdArray

final static protected callable itemTriu(int $col, int $k, int $count, int $line = 1)

Fill zeros from first item to a position

Parameters

int $col Stop column position
int $k Offset
int $count Max column position
int $line Start line for negative offsets

Return Value

callable

final static NdArray tril(NdArray|array $m, int $k = 0)

Lower triangle of an array

Parameters

NdArray|array $m
int $k Offset

Return Value

NdArray

final static protected callable itemTril(int $col, int $k, int $count, int $line = 1)

Fill zeros from a position to the end of the array

Parameters

int $col Start column position
int $k Offset
int $count Last column position
int $line Start line for negative offsets

Return Value

callable

final static NdArray tri(int $rows, int $cols = null, int $k = 0)

Construct an array with ones at and below the given diagonal and zeros elsewhere

Parameters

int $rows Number of rows
int $cols Number of columns
int $k Offset

Return Value

NdArray

final static protected callable itemTri(int $col, int $k, int $maxCols, int|null $line = 1)

Return a closure that fill a line item with ones

Parameters

int $col Position until which filling is done
int $k Offset
int $maxCols Max position to fill
int|null $line Start at this line if offset is negative

Return Value

callable

final static NdArray vander(NdArray|array $matrix, int $num = null)

Generate a Vandermonde matrix.

Parameters

NdArray|array $matrix A 1-dim array.
int $num Number of columns for the output.

Return Value

NdArray

Exceptions

InvalidArgumentException

final static protected callable itemVander(int $num)

Apply decreasing power on each row values

Parameters

int $num Number of wanted columns

Return Value

callable

static NdArray ar(array $data, string|null $identifier = null)

Construct a n-dimensional array

Parameters

array $data
string|null $identifier

Return Value

NdArray

static array parseArgs(array $args)

Parse args as a tuple or an array

Parameters

array $args

Return Value

array

static void transform(array|NdArray $m, bool $required = false)

Transform a PHP array in a NdArray

Parameters

array|NdArray $m
bool $required

Return Value

void

static bool allNumeric()

Check that all values are numeric

Return Value

bool