new NDArray(data, optionsopt)
Constructs or copies an NDArray instance.
Parameters
- data
-
options
Object
<optional>
Properties
-
shape
Array.<Number>
<optional>
-
length
Number
<optional>
-
strides
Array.<Number>
<optional>
-
dtype
string
<optional>
-
shape
Example
import { NDArray } from 'vectorious';
new NDArray() // => array([], dtype=float64)
new NDArray([]) // => array([], dtype=float64)
new NDArray([1, 2, 3]) // => array([1, 2, 3], dtype=float64)
new NDArray([[1, 2], [3, 4]]) // => array([ [ 1, 2 ], [ 3, 4 ] ], dtype=float64)
new NDArray(new Int32Array([1, 2, 3])) // => array([ 1, 2, 3 ], dtype=int32)
new NDArray([1, 2, 3, 4], {
shape: [2, 2],
dtype: 'uint32'
}) // => array([ [ 1, 2 ], [ 3, 4 ] ], dtype=uint32)
Source
Members
dataTypedArray
Type
-
TypedArray
Default Value
- new Float64Array(0)
Source
dtypeString
Type
-
String
Default Value
- 'float64'
Source
lengthNumber
Type
-
Number
Default Value
- 0
Source
shapeArray.<Number>
Type
-
Array.<Number>
Default Value
- [0]
Source
stridesArray.<Number>
Type
-
Array.<Number>
Default Value
- [0]
Source
TNDArray
Short for this.copy().transpose()
Type
Source
wNumber
Gets or sets the value at index 3
Type
-
Number
Source
xNumber
Gets or sets the value at index 0
Type
-
Number
Source
yNumber
Gets or sets the value at index 1
Type
-
Number
Source
zNumber
Gets or sets the value at index 2
Type
-
Number
Source
Methods
abs() → {this}
Returns the absolute value of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([-1, -2, -3]).abs() // <=> array([1, 2, 3])
Source
acos() → {this}
Returns the arccosine of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([-1, 0, 1]).acos(); // <=> array([3.141592653589793, 1.5707963267948966, 0])
Source
acosh(x) → {this}
Returns the hyperbolic arccosine of each element of current array.
Parameters
-
x
NDArray
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).acosh(); // <=> array([0, 1.316957950592041, 1.7627471685409546])
Source
add(x) → {NDArray}
Adds x
multiplied by alpha
to the current array.
Accelerated with BLAS ?axpy
.
Parameters
-
x
NDArray
Returns
-
NDArray
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).add([4, 5, 6]); // <=> array([5, 7, 9])
Source
angle(x) → {number}
Determines the angle between the current vector and x
.
Parameters
-
x
NDArray
Returns
-
number
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).angle([4, 5, 6]); // <=> 0.22572622788897287
Source
asin() → {this}
Returns the arcsine of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([-1, 0, 1]).asin() // <=> array([-1.5707963705062866, 0, 1.5707963705062866])
Source
asinh() → {this}
Returns the hyperbolic arcsine of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([0, 1, 2]).asinh() // <=> array([0, 0.8813735842704773, 1.4436354637145996])
Source
atan() → {this}
Returns the arctangent of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).atan() // <=> array([0.7853981852531433, 1.1071487665176392, 1.249045729637146])
Source
atanh() → {this}
Returns the hyperbolic arctangent of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([0, -0.5]).atanh(); // <=> array([0, -0.5493061542510986])
Source
augment(x) → {this}
Augments x
with current matrix.
Parameters
-
x
NDArray
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([[1, 2], [3, 4]]).augment(array([[1], [2]])); // <=> array([[1, 2, 1], [3, 4, 2]])
Source
binOp(x) → {this}
Perform binary operation f
on x
in the current array.
Parameters
-
x
NDArray
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).binOp([4, 5, 6], (a, b) => a + b); // => array([[5, 7, 9])
Source
cbrt() → {this}
Returns the cube root of each element of current array.
Returns
-
this
Example
import { cbrt } from 'vectorious/core/cbrt';
cbrt([1, 8, 27]); // => array([1, 2, 3])
Source
ceil() → {NDArray}
Returns smallest integer greater than or equal to of each element of current array.
Returns
-
NDArray
Example
import { array } from 'vectorious/core/array';
array([0.5, 1.5, 2.5]).ceil(); // <=> array([1, 2, 3])
Source
check()
Asserts if indices i, j, ..., n
are within the bounds of current array
Parameters
-
...indices
Array.<Number>
Example
import { array } from 'vectorious/core/array';
array([0.5, 1.5, 2.5]).check(3); // Error: index out of bounds
Throws
-
index out of bounds
- Type
-
Error
Source
combine(x) → {this}
Combines the current vector with x
Parameters
-
x
NDArray
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).combine([4, 5, 6]); // => array([1, 2, 3, 4, 5, 6])
Source
copy() → {NDArray}
Makes a copy of the class and underlying data
Returns
-
NDArray
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).copy(); // => array([1, 2, 3])
Source
cos() → {this}
Returns the cosine of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([0, Math.PI / 2, Math.PI]).cos(); // => array([1, 0, -1])
Source
cosh() → {this}
Returns the hyperbolic cosine of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([0, 1, 2]).cosh(); // => array([1, 1.5430806875228882, 3.762195587158203])
Source
cross(x) → {this}
Computes the cross product of the current vector and the vector x
This operation can only calculated for vectors with three components.
Otherwise it throws an exception.
Parameters
-
x
NDArray
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).cross([4, 5, 6]); // <=> array([-3, 6, -3])
Source
det() → {Number}
Gets the determinant of current matrix using LU factorization.
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([[0, 1], [2, 3]]).det(); // => -2
Source
diagonal() → {this}
Gets the diagonal of current matrix.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).diagonal(); // => array([1, 4])
Source
dot(x) → {Number}
Performs dot multiplication with x
and current array
Accelerated with BLAS ?dot
.
Parameters
-
x
NDArray
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).dot([4, 5, 6]); // => 32
Source
eig() → {Array.<NDArray>}
Gets eigenvalues and eigenvectors of the current matrix using the Jacobi method.
Accelerated with LAPACK ?geev
.
Returns
-
Array.<NDArray>
Example
import { array } from 'vectorious/core/array';
array([[1, 0, 0], [0, 2, 0], [0, 0, 3]]).eig(); // => [array([1, 2, 3]), array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])]
Source
equals(x, tolerance) → {Boolean}
Checks if current array and x
are equal.
Parameters
-
x
NDArray
-
tolerance
Number
Returns
-
Boolean
Example
import { equals } from 'vectorious/core/equals';
array([1, 2, 3]).equals([1, 2, 3]); // => true
Source
equidimensional(x)
Asserts if current array and x
have the same shape
Parameters
-
x
NDArray
Deprecated
- Yes
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).equidimensional([1, 2]); // Error: shapes 3 and 2 do not match
Throws
-
shapes x and y do not match
- Type
-
Error
Source
equilateral(x)
Asserts if current array and x
have the same length
Parameters
-
x
NDArray
Deprecated
- Yes
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).equilateral([1, 2]); // Error: lengths 3 and 2 do not match
Throws
-
lengths x and y do not match
- Type
-
Error
Source
exp() → {this}
Returns e^x of each element of current array, where x is the argument, and e is Euler's constant (2.718…), the base of the natural logarithm.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).exp(); // <=> array([2.7182817459106445, 7.389056205749512, 20.08553695678711])
Source
expm1() → {this}
Returns subtracting 1 from exp(x) of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).expm1(); // <=> array([1.7182817459106445, 6.389056205749512, 19.08553695678711])
Source
fill(value) → {this}
Fills the current array with a scalar value
Parameters
-
value
Number
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).fill(0); // <=> array([0, 0, 0])
Source
floor() → {this}
Returns the largest integer less than or equal to a number of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1.5, 2.5, 3.5]).floor(); // <=> array([1, 2, 3])
Source
forEach(f)
Equivalent to TypedArray.prototype.forEach
.
Parameters
-
f
function
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).forEach(console.log);
// 1 0 [ 1, 2, 3 ]
// 2 1 [ 1, 2, 3 ]
// 3 2 [ 1, 2, 3 ]
Source
fround() → {this}
Returns the nearest single precision float representation of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([-5.05, 5.05]).fround(); // <=> array([-5.050000190734863, 5.050000190734863])
Source
gauss() → {NDArray}
Gauss-Jordan elimination (i.e. returns the reduced row echelon form) of the current matrix.
Returns
-
NDArray
Example
import { array } from 'vectorious/core/array';
array([[1, 2, 3], [4, 5, 6]]).gauss(); // <=> array([[1, 0, -1], [-0, 1, 2]])
Source
get() → {Number}
Gets the element at i, j, ..., n
from current vector.
Parameters
-
...indices
Array.<Number>
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).get(2); // 3
Source
inv() → {this}
Determines the inverse of current matrix using Gaussian elimination.
Accelerated with LAPACK ?getri
.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([[2, -1, 0], [-1, 2, -1], [0, -1, 2]]).inv(); // <=> array([[0.75, 0.5, 0.25], [0.5, 1, 0.5], [0.25, 0.5, 0.75]])
Source
log() → {this}
Returns the natural logarithm (log_e, also ln) of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).log(); // <=> array([0, 0.6931471824645996, 1.0986123085021973])
Source
log1p() → {this}
Returns the natural logarithm (log_e, also ln) of 1 + x for each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]); // <=> array([0.6931471824645996, 1.0986123085021973, 1.3862943649291992])
Source
log2() → {this}
Returns the base 2 logarithm of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 4]).log2(); // => array([0, 1, 2])
Source
log10() → {this}
Returns the base 10 logarithm of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([10, 100, 1000]).log10(); // <=> array([1, 2, 3])
Source
lu() → {Array.<(NDArray|Int32Array)>}
Performs full LU decomposition on current matrix.
Accelerated with LAPACK ?getrf
.
Returns
-
Array.<(NDArray|Int32Array)>
Example
import { array } from 'vectorious/core/array';
array([[1, 3, 5], [2, 4, 7], [1, 1, 0]]).lu(); // => [array([[1, 0, 0], [0.5, 1, 0], [0.5, -1, 1]]), array([[2, 4, 7], [0, 1, 1.5], [0, 0, -2]]), Int32Array([2, 2, 3])]
Source
lu_factor() → {Array.<(NDArray|Int32Array)>}
Performs LU factorization on current matrix.
Accelerated with LAPACK ?getrf
.
Returns
-
Array.<(NDArray|Int32Array)>
Example
import { array } from 'vectorious/core/array';
array([[1, 3, 5], [2, 4, 7], [1, 1, 0]]).lu_factor(); // <=> [array([[2, 4, 7], [0.5, 1, 1.5], [0.5, -1, -2]]), Int32Array([2, 2, 3])]
Source
map() → {this}
Equivalent to TypedArray.prototype.map
.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).map(value => -value); // => array([-1, -2, -3])
Source
max() → {Number}
Gets the maximum value (smallest) element of current array.
Accelerated with BLAS i?amax
.
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).max(); // => 3
Source
mean() → {Number}
Gets the arithmetic mean of current array.
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).mean(); // => 2
Source
min() → {Number}
Gets the minimum value (smallest) element of current array.
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).min(); // 1
Source
multiply(x) → {NDArray}
Multiplies current matrix with x
.
Accelerated with BLAS ?gemm
.
Parameters
-
x
NDArray
Returns
-
NDArray
Example
import { array } from 'vectorious/core/array';
array([[1, 2]]).multiply([[1], [2]]); // <=> array([[5]])
Source
norm() → {Number}
Calculates the norm of current array (also called L2 norm or Euclidean length).
Accelerated with BLAS ?nrm2
.
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).norm(); // => 3.7416574954986572
Source
normalize() → {this}
Normalizes current vector.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).normalize(); // => array([0.26726123690605164, 0.5345224738121033, 0.8017836809158325])
Source
pow(exponent) → {this}
Returns each element of current array to the exponent power, that is, element^exponent.
Parameters
-
exponent
Number
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).pow(2); // <=> array([1, 4, 9])
Source
prod() → {Number}
Product of all elements of current array
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).prod(); // => 6
Source
product() → {NDArray}
Hadamard product of current matrix and x
Returns
-
NDArray
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).product([4, 5, 6]); // <=> array([4, 10, 18])
Source
project() → {NDArray}
Projects the current vector onto x
using the projection formula (y * (x * y / y * y))
.
Returns
-
NDArray
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).project([4, 5, 6]); // <=> array([1.6623376607894897, 2.0779221057891846, 2.49350643157959])
Source
push(value) → {this}
Pushes a new value
into current vector.
Parameters
-
value
Number
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).push(4); // => array([1, 2, 3, 4])
Source
rank(tolerance) → {Number}
Finds the rank of current matrix using gaussian elimination.
Parameters
-
tolerance
Number
To Do
- Switch to SVD algorithm
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([[1, 1, 1], [2, 2, 2], [3, 3, 3]]).rank(); // => 1
Source
reciprocal() → {this}
Gets the element-wise reciprocal of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]); // => array([1, 0.5, 0.3333333432674408])
Source
reduce(f, initialValue) → {Number}
Equivalent to TypedArray.prototype.reduce
.
Parameters
-
f
function
-
initialValue
Number
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).reduce((a, b) => a + b, 0); // => 6
Source
reshape() → {this}
Reshapes current array
Parameters
-
...shape
Array.<Number>
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3, 4]).reshape(2, 2); // <=> array([[1, 2], [3, 4]])
Source
round() → {this}
Returns the value of each element of current array rounded to the nearest integer.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1.2, 2.8, 3.5]).round(); // <=> array([1, 3, 4])
Source
row_add(dest, source, scalar) → {this}
Adds a multiple of one row multiplied by scalar
to another inside current matrix.
Parameters
-
dest
Number
-
source
Number
-
scalar
Number
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([[1, 2], [3, 4]]).row_add(1, 0, 2); // <=> array([[1, 2], [5, 8]])
Source
scale(scalar) → {this}
Multiplies all elements of current array with a specified scalar
.
Accelerated with BLAS ?scal
.
Parameters
-
scalar
Number
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).scale(2); // <=> array([2, 4, 6])
Source
set(value) → {this}
Sets the element at i, j, ..., n
to value
.
Parameters
-
...indices
Array.<Number>
-
value
Number
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).set(1, 0); // <=> array([1, 0, 3])
Source
sign() → {this}
Returns the sign of each element of current array, indicating whether it is positive, negative or zero.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).sign(); // <=> array([1, 1, 1])
Source
sin() → {this}
Returns the sine of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([0, Math.PI / 2, Math.PI]).sin(); // <=> array([0, 1, 0])
Source
sinh() → {this}
Returns the hyperbolic sine of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).sinh(); // <=> array([1.175201177597046, 3.6268603801727295, 10.017874717712402])
Source
slice(begin, end, step) → {this}
Slices the current array along the leading dimension
Parameters
-
begin
Number
-
end
Number
-
step
Number
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3, 4]).slice(0, 4, 2); // => array([1, 3])
Source
solve(x) → {NDArray}
Solves the equation AX = B (where A is current matrix and B is x
).
Accelerated with LAPACK ?gesv
.
Parameters
-
x
NDArray
Returns
-
NDArray
Example
import { array } from 'vectorious/core/array';
array([[1, 3, 5], [2, 4, 7], [1, 1, 0]]).solve([[1], [3], [5]]); // => array([[3.25], [1.75], [-1.5]])
Source
sqrt() → {this}
Returns the positive square root of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 4, 9]); // <=> array([1, 2, 3])
Source
square()
Asserts if current matrix is square.
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).square(); // Error: matrix is not square
Throws
-
matrix is not square
- Type
-
Error
Source
subtract() → {this}
Subtracts x
from the current array.
Accelerated with BLAS ?axpy
.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).subtract([1, 1, 1]); // <=> array([0, 1, 2])
Source
sum() → {Number}
Sum of array elements
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).sum(); // => 6
Source
swap(i, j) → {this}
Swaps two rows i
and j
in current matrix
Parameters
-
i
Number
-
j
Number
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([[1, 2], [3, 4]]); // <=> array([[3, 4], [1, 2]])
Source
tan() → {this}
Returns the tangent of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).tan(); // <=> array([1.5574077367782593, -2.185039758682251, -0.14254654943943024])
Source
tanh() → {this}
Returns the hyperbolic tangent of each element of current array.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).tanh(); // <=> array([0.7615941762924194, 0.9640275835990906, 0.9950547814369202])
Source
toArray(index, dim) → {Array}
Converts current vector into a JavaScript array.
Parameters
-
index
Number
-
dim
Number
Returns
-
Array
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).toArray(); // => [1, 2, 3]
Source
toString() → {String}
Converts current vector into a readable formatted string.
Returns
-
String
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).toString(); // => '1,2,3'
Source
trace() → {Number}
Gets the trace of the matrix (the sum of all diagonal elements).
Returns
-
Number
Example
import { array } from 'vectorious/core/array';
array([1, 2, 3]).trace(); // => 5
Source
transpose() → {this}
Transposes current matrix (mirror across the diagonal).
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]); // <=> array([[1, 4, 7], [2, 5, 8], [3, 6, 9]])
Source
trunc() → {this}
Returns the integer part of each element of current array, removing any fractional digits.
Returns
-
this
Example
import { array } from 'vectorious/core/array';
array([1.2, 2.8, 3.5]).trunc(); // => array([1, 2, 3])