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

x/vectorizer/src/utils/mod.ts>Matrix

Feature Extraction and Feature Selection in TypeScript
Go to Latest
class Matrix
implements Sliceable
import { Matrix } from "https://deno.land/x/vectorizer@v0.3.7/src/utils/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.

Constructors

new
Matrix(data: DType<T> | DTypeConstructor<T>, shape: [number, number])

Create a matrix from a typed array

Properties

data: DType<T>

Raw 1D TypedArray supplied

dType: DataType

Type of data in the matrix

readonly
html: string

Convert the Matrix into a HTML table

readonly
length: number
nCols: number

Number of columns in the matrix

nRows: number

Number of rows in the matrix

readonly
pretty: string

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

readonly
shape: [number, number]

Returns [rows, columns]

readonly
T: Matrix<T>

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

Methods

at(pos: number): DType<T>

Alias for row

col(n: number): DType<T>

Get the nth column in the matrix

cols(): Generator<DType<T>>

Iterate through columns

Get a column array of all column sums in the matrix

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

Get the dot product of two matrices

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

Filter the matrix by rows

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

Get an item using a row and column index

row(n: number): DType<T>

Get the nth row in the matrix

rows(): Generator<DType<T>>

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>)

Replace a column

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

Replace a row

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

Slice matrix by rows