Skip to content

Text 0.4.0 csrmatrix rowl1norm

github-actions[bot] edited this page Aug 21, 2026 · 1 revision

Lodestar.Text 0.4.0. This page is frozen at that release. Read the current documentation for what main says now. A link to a decision or a migration page follows main, and leaves the archive.

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