final class NdArray extends Decorator (View source)

Base array

Traits

Arithmetic methods
Attribute methods for NdArray
Basics for NdArray
Indexing methods for NdArray
Shape methods for NdArray
Visitor methods

Properties

array $data Access data as a PHP array.
NdArray $T Permute the dimensions of an array.
int $ndim Number of dimensions of an array.
int $size Number of elements of an array.
array $shape Tuple of array dimensions.

Methods

divide(NdArray|array|float|int $input)

Divide matrix by a given input, element-wise

dot(NdArray|array|float|int $input)

Dot matrix with an input

add(NdArray|array|float|int $input)

Add a matrix or a number

void
__set(string $name, mixed $value)

Attribute setter

int|array|NdArray
__get(string $name)

Generic getter

int
getSize()

Get the total number of elements of the array

array
getShape(int|float|array $data, array $shape)

Gets the dimensions of the array

copy()

Create a copy

mixed
offsetGet(string|int $index)

Get a view by index

offsetSet(int|string $index, int|string $value)

Set a view by index

int|float|array
filterGet(array $filter, int $index, array|null $data = null)

Get values from an element or a range

void
filterSet(array $filter, int $index, array|null $data = null, int|float $value = null)

Assign values to an element or a range

array
indexFilter(array $matches)

Prepare filter values

array
filterRange(array $filter, int $index, int $count)

Get range definition

bool
offsetUnset(mixed $offset)

Remove a portion of the data array

bool
offsetExists(mixed $offset)

Check that an index is defined

ravel()

Flattens data array

resize()

Resize array

reshape()

Reshapes data

walk(callable $func)

Walk on first dimension

walk_recursive(callable $func)

Walk on last dimension

int|float
iterate(RecursiveIteratorIterator $iterator)

Iterate on next value

int|NdArray
axis(callable $func, int|float $number = null, bool $keepdims = false)

Execute axis operations and return an aggregate

mixed
__call(string $name, array|null $arguments = null)

Call a np function

reciprocal()

Return the reciprocal of the argument, element-wise. {@link http://sciphp.org/ndarray.reciprocal}

int|float|array
trace(int $k)

Sum along diagonals {@link http://sciphp.org/ndarray.trace}.

tril(int $k)

Lower triangle of an array {@link http://sciphp.org/ndarray.tril}

triu(int $k)

Upper triangle of an array {@link http://sciphp.org/ndarray.triu}

vander(int $num = null)

Generate a Vandermonde matrix. {@link http://sciphp.org/ndarray.vander}

signbit()

Returns element-wise true where signbit is set (less than zero). {@link http://sciphp.org/ndarray.signbit}

log(int|float $base = M_E)

Natural logarithm, element-wise. {@link http://sciphp.org/ndarray.log}

log10()

Base-10 logarithm, element-wise. {@link http://sciphp.org/ndarray.log10}

log2()

Base-2 logarithm, element-wise. {@link http://sciphp.org/ndarray.log2}

negative()

Numerical negative, element-wise. {@link http://sciphp.org/ndarray.negative}

bool
is_square()

Is current matrix a square matrix. {@link http://sciphp.org/ndarray.is_square}

expm1()

Calculate exp(x) - 1 for all elements in the array. {@link http://sciphp.org/ndarray.expm1}

exp2()

Calculate 2**p for all p in the input array. {@link http://sciphp.org/ndarray.exp2}

power(float|int $exponent)

Matrix elements raised to powers. {@link http://sciphp.org/ndarray.power}

square()

The element-wise square of the input. {@link http://sciphp.org/ndarray.square}

sqrt()

The non-negative square-root of an array, element-wise. {@link http://sciphp.org/ndarray.sqrt}

int|float|array
trapz()

Integrate along the given axis using the composite trapezoidal rule. {@link http://sciphp.org/ndarray.trapz}

NdArray
sum(int|null $axis, bool $keepdims)

Sum all elements. {@link http://sciphp.org/ndarray.sum}

subtract(NdArray|array|float|int $input)

Subtract input from matrix. {@link http://sciphp.org/ndarray.subtract}

multiply(NdArray|array|float|int $input)

Multiply matrix by a given input, element-wise. {@link http://sciphp.org/ndarray.multiply}

copysign(NdArray|array|float|int $m)

Change the sign to that of given matrix, element-wise. {@link http://sciphp.org/ndarray.copysign}

cos()

Cosine element-wise. {@link http://sciphp.org/ndarray.cos}

sin()

Trigonometric sine, element-wise. {@link http://sciphp.org/ndarray.sin}

tan()

Compute tangent element-wise. {@link http://sciphp.org/ndarray.tan}

transform()

Transform a PHP array in a NdArray if needed

__construct(array $data, string|null $identifier = null)

Constructor

string
__toString()

Pretty printer

Details

final NdArray divide(NdArray|array|float|int $input)

Divide matrix by a given input, element-wise

Parameters

NdArray|array|float|int $input

Return Value

NdArray

final NdArray dot(NdArray|array|float|int $input)

Dot matrix with an input

Parameters

NdArray|array|float|int $input

Return Value

NdArray

final NdArray add(NdArray|array|float|int $input)

Add a matrix or a number

Parameters

NdArray|array|float|int $input

Return Value

NdArray

final void __set(string $name, mixed $value)

Attribute setter

Parameters

string $name
mixed $value

Return Value

void

final int|array|NdArray __get(string $name)

Generic getter

Parameters

string $name

Return Value

int|array|NdArray

Exceptions

InvalidAttributeException

final protected int getSize()

Get the total number of elements of the array

Return Value

int

final protected array getShape(int|float|array $data, array $shape)

Gets the dimensions of the array

Parameters

int|float|array $data Axis
array $shape

Return Value

array

final NdArray copy()

Create a copy

Return Value

NdArray

final mixed offsetGet(string|int $index)

Get a view by index

Parameters

string|int $index

Return Value

mixed

final NdArray offsetSet(int|string $index, int|string $value)

Set a view by index

Parameters

int|string $index
int|string $value

Return Value

NdArray

final protected int|float|array filterGet(array $filter, int $index, array|null $data = null)

Get values from an element or a range

Parameters

array $filter
int $index
array|null $data

Return Value

int|float|array

final protected void filterSet(array $filter, int $index, array|null $data = null, int|float $value = null)

Assign values to an element or a range

Parameters

array $filter
int $index
array|null $data
int|float $value

Return Value

void

final protected array indexFilter(array $matches)

Prepare filter values

Parameters

array $matches

Return Value

array

final protected array filterRange(array $filter, int $index, int $count)

Get range definition

Parameters

array $filter
int $index
int $count

Return Value

array

final bool offsetUnset(mixed $offset)

Remove a portion of the data array

Parameters

mixed $offset

Return Value

bool

final bool offsetExists(mixed $offset)

Check that an index is defined

Parameters

mixed $offset

Return Value

bool

final NdArray ravel()

Flattens data array

Return Value

NdArray

final NdArray resize()

Resize array

Return Value

NdArray

final NdArray reshape()

Reshapes data

Return Value

NdArray

Exceptions

InvalidArgumentException if shape parameter has a different size

final NdArray walk(callable $func)

Walk on first dimension

Parameters

callable $func

Return Value

NdArray

final NdArray walk_recursive(callable $func)

Walk on last dimension

Parameters

callable $func

Return Value

NdArray

final int|float iterate(RecursiveIteratorIterator $iterator)

Iterate on next value

Parameters

RecursiveIteratorIterator $iterator

Return Value

int|float

final int|NdArray axis(callable $func, int|float $number = null, bool $keepdims = false)

Execute axis operations and return an aggregate

Parameters

callable $func
int|float $number
bool $keepdims

Return Value

int|NdArray

final mixed __call(string $name, array|null $arguments = null)

Call a np function

Parameters

string $name
array|null $arguments

Return Value

mixed

NdArray reciprocal()

Return the reciprocal of the argument, element-wise. {@link http://sciphp.org/ndarray.reciprocal}

Return Value

NdArray

int|float|array trace(int $k)

Sum along diagonals {@link http://sciphp.org/ndarray.trace}.

Parameters

int $k

Return Value

int|float|array

NdArray tril(int $k)

Lower triangle of an array {@link http://sciphp.org/ndarray.tril}

Parameters

int $k

Return Value

NdArray

NdArray triu(int $k)

Upper triangle of an array {@link http://sciphp.org/ndarray.triu}

Parameters

int $k

Return Value

NdArray

NdArray vander(int $num = null)

Generate a Vandermonde matrix. {@link http://sciphp.org/ndarray.vander}

Parameters

int $num

Return Value

NdArray

NdArray signbit()

Returns element-wise true where signbit is set (less than zero). {@link http://sciphp.org/ndarray.signbit}

Return Value

NdArray

NdArray log(int|float $base = M_E)

Natural logarithm, element-wise. {@link http://sciphp.org/ndarray.log}

Parameters

int|float $base

Return Value

NdArray

NdArray log10()

Base-10 logarithm, element-wise. {@link http://sciphp.org/ndarray.log10}

Return Value

NdArray

NdArray log2()

Base-2 logarithm, element-wise. {@link http://sciphp.org/ndarray.log2}

Return Value

NdArray

NdArray negative()

Numerical negative, element-wise. {@link http://sciphp.org/ndarray.negative}

Return Value

NdArray

bool is_square()

Is current matrix a square matrix. {@link http://sciphp.org/ndarray.is_square}

Return Value

bool

NdArray expm1()

Calculate exp(x) - 1 for all elements in the array. {@link http://sciphp.org/ndarray.expm1}

Return Value

NdArray

NdArray exp2()

Calculate 2**p for all p in the input array. {@link http://sciphp.org/ndarray.exp2}

Return Value

NdArray

NdArray power(float|int $exponent)

Matrix elements raised to powers. {@link http://sciphp.org/ndarray.power}

Parameters

float|int $exponent

Return Value

NdArray

NdArray square()

The element-wise square of the input. {@link http://sciphp.org/ndarray.square}

Return Value

NdArray

NdArray sqrt()

The non-negative square-root of an array, element-wise. {@link http://sciphp.org/ndarray.sqrt}

Return Value

NdArray

int|float|array trapz()

Integrate along the given axis using the composite trapezoidal rule. {@link http://sciphp.org/ndarray.trapz}

Return Value

int|float|array

NdArray sum(int|null $axis, bool $keepdims)

Sum all elements. {@link http://sciphp.org/ndarray.sum}

Parameters

int|null $axis
bool $keepdims

Return Value

NdArray

NdArray subtract(NdArray|array|float|int $input)

Subtract input from matrix. {@link http://sciphp.org/ndarray.subtract}

Parameters

NdArray|array|float|int $input

Return Value

NdArray

NdArray multiply(NdArray|array|float|int $input)

Multiply matrix by a given input, element-wise. {@link http://sciphp.org/ndarray.multiply}

Parameters

NdArray|array|float|int $input

Return Value

NdArray

NdArray copysign(NdArray|array|float|int $m)

Change the sign to that of given matrix, element-wise. {@link http://sciphp.org/ndarray.copysign}

Parameters

NdArray|array|float|int $m

Return Value

NdArray

NdArray cos()

Cosine element-wise. {@link http://sciphp.org/ndarray.cos}

Return Value

NdArray

NdArray sin()

Trigonometric sine, element-wise. {@link http://sciphp.org/ndarray.sin}

Return Value

NdArray

NdArray tan()

Compute tangent element-wise. {@link http://sciphp.org/ndarray.tan}

Return Value

NdArray

NdArray transform()

Transform a PHP array in a NdArray if needed

Return Value

NdArray

__construct(array $data, string|null $identifier = null)

Constructor

Parameters

array $data
string|null $identifier A NdArray identifier

string __toString()

Pretty printer

Return Value

string