Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/vectorizer/src/mod.ts>Matrix

Machine Learning utilities for TypeScript
Latest
class Matrix
implements Sliceable, MatrixLike<DT>
extends Tensor<DT, 2>
Re-export
import { Matrix } from "https://deno.land/x/vectorizer@v0.7.5/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
)

Type Parameters

DT extends DataType

Properties

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.

Methods

at(pos: number): DType<DT>

Alias for row

col(n: number): DType<DT>

Get the nth column in the matrix

colMean(): DType<DT>
cols(): Generator<DType<DT>>

Iterate through columns

colSum(): DType<DT>

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

rowMean(): DType<DT>
rows(): Generator<DType<DT>>

Iterate through rows

rowSum(): DType<DT>

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>