Skip to content
@teakit/matrix documentation

Matrix products

Multiply matrices with the mmul method.

Example

Pass rows to the Matrix constructor. To multiply two matrices, the number of columns on the left must equal the number of rows on the right.

ts
import { Matrix } from "@teakit/matrix";

const counts = new Matrix([[2, 3], [4, 1]]);
const prices = new Matrix([[10], [5]]);
const totals = counts.mmul(prices);
totals.get(0, 0); // 35
totals.get(1, 0); // 45

Each output entry is the dot product of a row of counts and a column of prices. Here the two input rows produce two totals.