Methods
(static) checkBounds(lb, ub) → {matrix}
Returns a element-wise matrix checking each element against upper and lower bound.
- 0, no bound violation
- -1, lower bound violation
- 1, upper bound violation
Example
var M = require('./src/matrix_lib');
var A = new M([[1,2,3,4]]);
console.log(A.checkBounds(1.5,2.5).print());
// Result
//-1.000 0.000 1.000 1.000
Parameters:
| Name | Type | Description |
|---|---|---|
lb |
double | Lower bound |
ub |
double | Upper bound |
Returns:
- Type
- matrix
(static) diag() → {matrix}
Converts a column/row matrix into a diagonal 2d matrix
Example
var M = require('./src/matrix_lib');
console.log(M.range(3).diag().print());
//0.000 0.000 0.000
//0.000 1.000 0.000
//0.000 0.000 2.000
Returns:
- Type
- matrix
(static) flatten() → {array}
- Source:
Flattens / unrolls a matrix from 2d to 1d
Example
var M = require('./src/matrix_lib');
var A = new M([[1,2],[3,4]]);
A.flatten()
// res: [ 1, 2, 3, 4 ]
Returns:
- Type
- array
(static) length() → {int}
Returns the max dimension of a matrix
Returns:
- Type
- int
(static) max() → {double}
Returns the max value of a matrix
Returns:
- Type
- double
(static) min() → {double}
Returns the minimal value of a matrix
Returns:
- Type
- double
(static) print() → {string}
Flattens / unrolls a matrix from 2d to 1d
Returns:
- Type
- string
(static) round(d) → {int}
Returns the matrix rounded to the specified decimal place
Parameters:
| Name | Type | Description |
|---|---|---|
d |
decimal precision |
Returns:
- Type
- int
(static) sum() → {double}
Returns the sum of a matrix
Returns:
- Type
- double