Skip to content

Text csrmatrix rowl1norm

github-actions[bot] edited this page Aug 26, 2026 · 24 revisions

Development build. This page describes main, not a released package. The latest published Lodestar.Text is 0.4.0 — read its documentation.

CsrMatrix.RowL1Norm

The sum of one row's absolute values — its total mass.

public double RowL1Norm(int row)

Parametersrow is the zero-based row index.

Returnsdouble, the sum of |value| over that row's stored cells. Zero for an empty row.

ExceptionsIndexOutOfRangeException when row is negative or not below RowCount. The index reaches the backing array directly, so the array's own exception is what surfaces rather than a re-wrapped one.

Example — on raw counts, the L1 norm is how many terms the document holds.

using Lodestar.Text.Vectorization;

string[] docs = ["the cat eats", "the dog eats", "the cat and the dog"];
CsrMatrix counts = new CountVectorizer().FitTransform(docs);

double first = counts.RowL1Norm(0);   // => 3
double third = counts.RowL1Norm(2);   // => 5

Remarks — absolute values, which matters only where a matrix can hold negatives: HashingVectorizer with AlternateSign on produces them by design, and there the L1 norm is the total weight rather than a net one.

Dividing a row by this norm turns it into a distribution over terms, which is what NormalizeRows(SparseNorm.L1) does.

Applies to — net10.0, netstandard2.0.

See alsoCsrMatrix.RowL2Norm, CsrMatrix.NormalizeRows, SparseNorm.

Lodestar

Project

Clone this wiki locally