Matrix norms
Overview
The norm function computes the norm of a matrix or vector. The norm type is selected via the Norm enum.
Norm types
Enum value | Formula | Description |
|---|---|---|
| sqrt(sum of \|a_ij\|^2) | Frobenius norm (square root of sum of squares). Default. |
| max over columns of sum \|a_ij\| | Maximum column sum (1-norm). |
| max over rows of sum \|a_ij\| | Maximum row sum (infinity norm). |
| max(\|a_ij\|) | Maximum absolute element value. |
Signatures
// Double matrix
fun LinAlg.norm(mat: MultiArray<Double, D2>, norm: Norm = Norm.Fro): Double
// Float matrix
fun LinAlg.norm(mat: MultiArray<Float, D2>, norm: Norm = Norm.Fro): Float
// Double vector
fun LinAlg.norm(mat: MultiArray<Double, D1>, norm: Norm = Norm.Fro): Double
// Float vector
fun LinAlg.norm(mat: MultiArray<Float, D1>, norm: Norm = Norm.Fro): Float
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Input matrix or vector. |
|
| Norm type. Default: |
Returns: Double or Float — the computed norm value.
Example
val a = mk.ndarray(mk[mk[1.0, 2.0], mk[3.0, 4.0]])
mk.linalg.norm(a) // Frobenius: sqrt(1+4+9+16) = sqrt(30) ≈ 5.477
mk.linalg.norm(a, Norm.N1) // max column sum: max(4, 6) = 6.0
mk.linalg.norm(a, Norm.Inf) // max row sum: max(3, 7) = 7.0
mk.linalg.norm(a, Norm.Max) // max |element|: 4.0
Vector norm
val v = mk.ndarray(mk[3.0, 4.0])
mk.linalg.norm(v) // Frobenius: sqrt(9+16) = 5.0
19 February 2026