Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/netsaur/packages/utilities/src/mod.ts>Matrix

Powerful Powerful Machine Learning library with GPU, CPU and WASM backends
Latest
class Matrix
implements Sliceable, MatrixLike<DT>
extends Tensor<DT, 2>
Re-export
import { Matrix } from "https://deno.land/x/netsaur@0.4.2/packages/utilities/src/mod.ts";

Class for 2D Arrays. This is not akin to a mathematical Matrix (a collection of column vectors). This is a collection of row vectors. A special case of Tensor for 2D data.

Constructors

new
Matrix(matrix: TensorLike<DT, 2>)

Create a matrix from a typed array

new
Matrix(array: NDArray<DT>[2], dType: DT)
new
Matrix(data: DType<DT>, shape: Shape<2>)
new
Matrix(dType: DT, shape: Shape<2>)
new
Matrix(data:
| NDArray<DT>[2]
| DType<DT>
| DT
| TensorLike<DT, 2>
, shape?: Shape<2> | DT
)

Properties

readonly
head: Matrix<DT>
readonly
html: string

Convert the Matrix into a HTML table

readonly
length: number
readonly
nCols: number

Returns number of cols

readonly
nRows: number

Returns number of rows

readonly
pretty: string

Get a pretty version for printing. DO NOT USE FOR MATRICES WITH MANY COLUMNS.

readonly
T: Matrix<DT>

Get the transpose of the matrix. This method clones the matrix.

readonly
tail: Matrix<DT>

Methods

at(pos: number): DType<DT>

Alias for row

col(n: number): DType<DT>

Get the nth column in the matrix

cols(): Generator<DType<DT>>

Iterate through columns

Get a column array of all column sums in the matrix

dot(rhs: Matrix<DT>): number | bigint

Get the dot product of two matrices

filter(fn: (
value: DType<DT>,
row: number,
_: DType<DT>[],
) => boolean
): Matrix<DT>

Filter the matrix by rows

item(row: number, col: number): DTypeValue<DT>

Get an item using a row and column index

row(n: number): DType<DT>

Get the nth row in the matrix

rows(): Generator<DType<DT>>

Iterate through rows

Compute the sum of all rows

setAdd(
row: number,
col: number,
val: number | bigint,
)

Add a value to an existing element Will throw an error if the types mismatch

setCell(
row: number,
col: number,
val: number,
)

Set a value in the matrix

setCol(col: number, val: ArrayLike<number>): number

Replace a column

setRow(row: number, val: ArrayLike<number> | ArrayLike<bigint>)

Replace a row

slice(start?, end?: number): Matrix<DT>

Slice matrix by rows

[Symbol.for("Jupyter.display")](): Record<string, string>