Linear algebra: matrices, systems of equations, decompositions, eigenvalues and statistics.
Functions
func Transpose (x &: Matrix): Matrix matrix-Math.salam Copy
import matrix
func build (rows: int , cols: int , numbers: str ): matrix.Matrix:
mut data := Vector {} as Vector < f64 >
each number in numbers. Split ( " " ):
data. Push (number. ToFloat ())
end
ret matrix. FromArray (rows, cols, data)
end
func show (name: str , m &: matrix.Matrix):
println name, matrix. ToRepr (m, 1 )
end
func r (value: f64 ): str :
ret matrix. ToStringPrec (matrix. Full ( 1 , 1 , value), 3 )
end
func main :
mut a := build ( 2 , 2 , "1 2 3 4" )
mut b := build ( 2 , 2 , "0 1 1 0" )
mut row := build ( 1 , 2 , "10 20" )
mut col := build ( 2 , 1 , "1 -1" )
show ( "Transpose" , matrix. Transpose (a))
show ( "MatMul" , matrix. MatMul (a, b))
mut out := matrix. Zeros ( 2 , 2 )
println matrix. TransposeInto (a, out), matrix. MatMulInto (a, b, out)
show ( "into" , out)
show ( "TransposeMul" , matrix. TransposeMul (a, b))
show ( "MulTranspose" , matrix. MulTranspose (a, b))
show ( "Gram" , matrix. Gram (a))
show ( "MatVec" , matrix. MatVec (a, col))
show ( "VecMat" , matrix. VecMat (row, a))
println matrix. Dot (col, col), matrix. Trace (a)
show ( "Outer" , matrix. Outer (col, col))
show ( "Kron" , matrix. Kron (matrix. Eye ( 2 ), matrix. Full ( 1 , 2 , 3.0 )))
show ( "MatPow" , matrix. MatPow (a, 2 ))
show ( "Cross3" , matrix. Cross3 ( build ( 3 , 1 , "1 0 0" ), build ( 3 , 1 , "0 1 0" )))
show ( "Add" , matrix. Add (a, b))
show ( "Sub" , matrix. Sub (a, b))
show ( "MulElem" , matrix. MulElem (a, b))
show ( "DivElem" , matrix. DivElem (a, a))
show ( "Neg" , matrix. Neg (a))
show (
"with scalars" ,
matrix. AddScalar (matrix. SubScalar (matrix. Scale (matrix. DivScalar (a, 2.0 ), 4.0 ), 1.0 ), 1.0 )
)
mut c := matrix. Clone (a)
matrix. AddInPlace (c, b)
matrix. SubInPlace (c, b)
matrix. MulElemInPlace (c, a)
matrix. ScaleInPlace (c, 0.5 )
matrix. AddScalarInPlace (c, 1.0 )
matrix. NegInPlace (c)
matrix. AddScaled (c, a, 2.0 )
show ( "in place" , c)
show ( "Combine" , matrix. Combine (a, 2.0 , b, - 1.0 ))
show ( "MaxElem" , matrix. MaxElem (a, matrix. Full ( 2 , 2 , 2.5 )))
show ( "MinElem" , matrix. MinElem (a, matrix. Full ( 2 , 2 , 2.5 )))
show ( "AddRowVector" , matrix. AddRowVector (a, row))
show ( "AddColVector" , matrix. AddColVector (a, col))
show ( "MulRowVector" , matrix. MulRowVector (a, row))
show ( "MulColVector" , matrix. MulColVector (a, col))
mut m := build ( 1 , 4 , "-2.25 0 0.5 9" )
show ( "Abs" , matrix. Abs (m))
show ( "Sqrt" , matrix. Sqrt (matrix. Abs (m)))
show ( "Cbrt" , matrix. Cbrt ( build ( 1 , 2 , "8 -27" )))
show ( "Floor and Ceil" , matrix. HStack (matrix. Floor (m), matrix. Ceil (m)))
show ( "Round and Trunc" , matrix. HStack (matrix. Round (m), matrix. Trunc (m)))
show ( "Sign" , matrix. Sign (m))
show ( "Square" , matrix. Square (m))
show ( "Reciprocal" , matrix. Reciprocal ( build ( 1 , 2 , "2 4" )))
show ( "PowElem" , matrix. PowElem ( build ( 1 , 2 , "2 3" ), 3.0 ))
show ( "Clip" , matrix. Clip (m, 0.0 , 1.0 ))
show (
"MaxScalar and MinScalar" , matrix. HStack (matrix. MaxScalar (m, 0.0 ), matrix. MinScalar (m, 0.0 ))
)
show ( "Chop" , matrix. Chop ( build ( 1 , 2 , "0.0000001 1" ), 0.0001 ))
mut zero := matrix. Zeros ( 1 , 1 )
println matrix. ToStringPrec (matrix. HStack (matrix. Exp (zero), matrix. Log (matrix. Ones ( 1 , 1 ))), 3 ),
matrix. ToStringPrec (matrix. Log10 (matrix. Full ( 1 , 1 , 100.0 )), 3 ),
matrix. ToStringPrec (matrix. Log2 (matrix. Full ( 1 , 1 , 8.0 )), 3 )
println matrix. ToStringPrec (matrix. HStack (matrix. Sin (zero), matrix. Cos (zero)), 3 ),
matrix. ToStringPrec (matrix. Tan (zero), 3 )
println matrix. ToStringPrec (
matrix. HStack (matrix. Asin (zero), matrix. Acos (matrix. Ones ( 1 , 1 ))), 3
),
matrix. ToStringPrec (matrix. Atan (zero), 3 )
println matrix. ToStringPrec (matrix. HStack (matrix. Sinh (zero), matrix. Cosh (zero)), 3 ),
matrix. ToStringPrec (matrix. Tanh (zero), 3 )
println matrix. Sum (a),
matrix. Prod (a),
matrix. Mean (a),
matrix. Min (a),
matrix. Max (a),
matrix. Range (a)
k := matrix. ArgMax (a)
println matrix. ArgMin (a), k, matrix. IndexRow (a, k), matrix. IndexCol (a, k), matrix. MaxAbs (m)
println r (matrix. Var (a, true )), r (matrix. Std (a, false )), matrix. Median (a)
show ( "RowSums" , matrix. RowSums (a))
show ( "ColSums" , matrix. ColSums (a))
show ( "RowMeans" , matrix. RowMeans (a))
show ( "ColMeans" , matrix. ColMeans (a))
show ( "RowMins and RowMaxs" , matrix. HStack (matrix. RowMins (a), matrix. RowMaxs (a)))
show ( "ColMins and ColMaxs" , matrix. VStack (matrix. ColMins (a), matrix. ColMaxs (a)))
show ( "cumulative" , matrix. HStack (matrix. CumSumRows (a), matrix. CumSumCols (a)))
show ( "CumProdRows" , matrix. CumProdRows (a))
println matrix. CountNonZero (b), matrix. Any (b), matrix. All (b), matrix. AllFinite (b)
println r (matrix. NormFrobenius (a)), matrix. Norm1 (a), matrix. NormInf (a), matrix. NormMax (a)
println r (matrix. Norm2 (a)),
r (matrix. NormNuclear (a)),
matrix. VecNorm (col, 1.0 ),
r (matrix. Distance (col, matrix. Zeros ( 2 , 1 )))
show ( "Normalize" , matrix. Normalize ( build ( 1 , 2 , "3 4" )))
println matrix. ToStringPrec (matrix. NormalizeRows (a), 2 )
println matrix. ToStringPrec (matrix. NormalizeCols (a), 2 )
println r (matrix. Cond1 (a)), r (matrix. CondInf (a)), r (matrix. Cond2 (a))
end Output Transpose [1.0,3.0; 2.0,4.0]
MatMul [2.0,1.0; 4.0,3.0]
true true
into [2.0,1.0; 4.0,3.0]
TransposeMul [3.0,1.0; 4.0,2.0]
MulTranspose [2.0,1.0; 4.0,3.0]
Gram [10.0,14.0; 14.0,20.0]
MatVec [-1.0; -1.0]
VecMat [70.0,100.0]
2 5
Outer [1.0,-1.0; -1.0,1.0]
Kron [3.0,3.0,0.0,0.0; 0.0,0.0,3.0,3.0]
MatPow [7.0,10.0; 15.0,22.0]
Cross3 [0.0; 0.0; 1.0]
Add [1.0,3.0; 4.0,4.0]
Sub [1.0,1.0; 2.0,4.0]
MulElem [0.0,2.0; 3.0,0.0]
DivElem [1.0,1.0; 1.0,1.0]
Neg [-1.0,-2.0; -3.0,-4.0]
with scalars [2.0,4.0; 6.0,8.0]
in place [0.5,1.0; 0.5,-1.0]
Combine [2.0,3.0; 5.0,8.0]
MaxElem [2.5,2.5; 3.0,4.0]
MinElem [1.0,2.0; 2.5,2.5]
AddRowVector [11.0,22.0; 13.0,24.0]
AddColVector [2.0,3.0; 2.0,3.0]
MulRowVector [10.0,40.0; 30.0,80.0]
MulColVector [1.0,2.0; -3.0,-4.0]
Abs [2.3,0.0,0.5,9.0]
Sqrt [1.5,0.0,0.7,3.0]
Cbrt [2.0,-3.0]
Floor and Ceil [-3.0,0.0,0.0,9.0,-2.0,0.0,1.0,9.0]
Round and Trunc [-2.0,0.0,1.0,9.0,-2.0,0.0,0.0,9.0]
Sign [-1.0,0.0,1.0,1.0]
Square [5.1,0.0,0.3,81.0]
Reciprocal [0.5,0.3]
PowElem [8.0,27.0]
Clip [0.0,0.0,0.5,1.0]
MaxScalar and MinScalar [0.0,0.0,0.5,9.0,-2.3,0.0,0.0,0.0]
Chop [0.0,1.0]
1.000 0.000 2.000 3.000
0.000 1.000 0.000
0.000 0.000 0.000
0.000 1.000 0.000
10 24 2.5 1 4 3
0 3 1 1 9
1.667 1.118 2.5
RowSums [3.0; 7.0]
ColSums [4.0,6.0]
RowMeans [1.5; 3.5]
ColMeans [2.0,3.0]
RowMins and RowMaxs [1.0,2.0; 3.0,4.0]
ColMins and ColMaxs [1.0,2.0; 3.0,4.0]
cumulative [1.0,3.0,1.0,2.0; 3.0,7.0,4.0,6.0]
CumProdRows [1.0,2.0; 3.0,12.0]
2 true false true
5.477 6 7 4
5.465 5.831 2 1.414
Normalize [0.6,0.8]
0.45 0.89
0.60 0.80
0.32 0.45
0.95 0.89
21.000 21.000 14.933
func MatMul (x &: Matrix, y &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func TransposeInto (x &: Matrix, out &: Matrix): bool The transpose into a ready matrix.
The example for this item is shown with the ones above: matrix-Math.salam
func MatMulInto (x &: Matrix, y &: Matrix, out &: Matrix): bool The product into a ready matrix.
The example for this item is shown with the ones above: matrix-Math.salam
func TransposeMul (x &: Matrix, y &: Matrix): Matrix The transpose of x times y.
The example for this item is shown with the ones above: matrix-Math.salam
func MulTranspose (x &: Matrix, y &: Matrix): Matrix x times the transpose of y.
The example for this item is shown with the ones above: matrix-Math.salam
func Gram (x &: Matrix): Matrix The Gram matrix, the transpose of x times x.
The example for this item is shown with the ones above: matrix-Math.salam
func MatVec (a &: Matrix, x &: Matrix): Matrix A matrix times a column vector.
The example for this item is shown with the ones above: matrix-Math.salam
func VecMat (x &: Matrix, a &: Matrix): Matrix A row vector times a matrix.
The example for this item is shown with the ones above: matrix-Math.salam
func Dot (x &: Matrix, y &: Matrix): f64 The dot product of two vectors.
The example for this item is shown with the ones above: matrix-Math.salam
func Outer (u &: Matrix, v &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func Kron (x &: Matrix, y &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func MatPow (x &: Matrix, k: int ): Matrix An integer power of a square matrix.
The example for this item is shown with the ones above: matrix-Math.salam
func Trace (x &: Matrix): f64 The trace, the sum of the diagonal.
The example for this item is shown with the ones above: matrix-Math.salam
func Cross3 (u &: Matrix, v &: Matrix): Matrix The three dimensional cross product.
The example for this item is shown with the ones above: matrix-Math.salam
func NewRng (seed: i64 ): Rng The example for this item is shown with the ones above: matrix-Stats.salam
func Hilbert (n: int ): Matrix The Hilbert matrix; the famous example of an ill conditioned matrix.
The example for this item is shown with the ones above: matrix-Stats.salam
func HilbertInverse (n: int ): Matrix The exact inverse of the Hilbert matrix.
The example for this item is shown with the ones above: matrix-Stats.salam
func Vandermonde (x &: Matrix, cols: int ): Matrix The Vandermonde matrix; for polynomial interpolation.
The example for this item is shown with the ones above: matrix-Stats.salam
func Toeplitz (first_col &: Matrix, first_row &: Matrix): Matrix A Toeplitz matrix from its first column and row.
The example for this item is shown with the ones above: matrix-Eigen.salam
func Hankel (first_col &: Matrix, last_row &: Matrix): Matrix A Hankel matrix from its first column and last row.
The example for this item is shown with the ones above: matrix-Eigen.salam
func Circulant (c &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Stats.salam
func Companion (coeffs &: Matrix): Matrix The companion matrix of a polynomial with coefficients from degree zero; its eigenvalues are the roots.
The example for this item is shown with the ones above: matrix-Stats.salam
func Pascal (n: int ): Matrix The example for this item is shown with the ones above: matrix-Stats.salam
func Rotation2D (theta: f64 ): Matrix A two dimensional rotation by an angle in radians.
The example for this item is shown with the ones above: matrix-Stats.salam
func Rotation3D (axis: int , theta: f64 ): Matrix A three dimensional rotation about axis 0, 1 or 2.
The example for this item is shown with the ones above: matrix-Stats.salam
func Householder (v &: Matrix): Matrix A Householder reflection.
The example for this item is shown with the ones above: matrix-Stats.salam
func Givens (n: int , p: int , q: int , theta: f64 ): Matrix A Givens rotation in the p and q plane.
The example for this item is shown with the ones above: matrix-Stats.salam
func Permutation (perm &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Stats.salam
func Random (rows: int , cols: int , lo: f64 , hi: f64 , seed: i64 ): Matrix A uniform random matrix from a seed.
The example for this item is shown with the ones above: matrix-Eigen.salam
func RandomNormal (rows: int , cols: int , seed: i64 ): Matrix The example for this item is shown with the ones above: matrix-Stats.salam
func RandomSymmetric (n: int , seed: i64 ): Matrix A random symmetric matrix.
The example for this item is shown with the ones above: matrix-Stats.salam
func RandomSPD (n: int , seed: i64 ): Matrix A random positive definite matrix.
The example for this item is shown with the ones above: matrix-Stats.salam
func RandomOrthogonal (n: int , seed: i64 ): Matrix A random orthogonal matrix.
The example for this item is shown with the ones above: matrix-Stats.salam
func Hessenberg (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Eigen.salam
func EigVals (x &: Matrix): Eigen The eigenvalues by the QR method.
The example for this item is shown with the ones above: matrix-Eigen.salam
func EigValsAuto (x &: Matrix): Eigen The eigenvalues by whichever method suits the matrix, symmetric or general.
The example for this item is shown with the ones above: matrix-Eigen.salam
func SpectralRadius (x &: Matrix): f64 The greatest absolute eigenvalue.
The example for this item is shown with the ones above: matrix-Eigen.salam
func CharPoly (x &: Matrix): Matrix The coefficients of the characteristic polynomial from degree zero.
The example for this item is shown with the ones above: matrix-Eigen.salam
func EigVecFor (x &: Matrix, lambda: f64 , iters: int ): Matrix The eigenvector for one eigenvalue.
The example for this item is shown with the ones above: matrix-Eigen.salam
func RowEchelon (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Solve.salam
func RREF (x &: Matrix): Matrix The reduced row echelon form.
The example for this item is shown with the ones above: matrix-Solve.salam
func PivotColumns (x &: Matrix): Matrix The indices of the pivot columns.
The example for this item is shown with the ones above: matrix-Solve.salam
func RankExact (x &: Matrix): int The rank by Gaussian elimination.
The example for this item is shown with the ones above: matrix-Solve.salam
func Nullity (x &: Matrix): int The dimension of the null space.
The example for this item is shown with the ones above: matrix-Solve.salam
func NullSpaceExact (x &: Matrix): Matrix A basis of the null space from the echelon form.
The example for this item is shown with the ones above: matrix-Solve.salam
func ColumnSpaceExact (x &: Matrix): Matrix A basis of the column space from the pivot columns.
The example for this item is shown with the ones above: matrix-Solve.salam
func SolveGeneral (a &: Matrix, b &: Matrix): Matrix One solution of the system, even when the matrix is singular.
The example for this item is shown with the ones above: matrix-Solve.salam
func IsConsistent (a &: Matrix, b &: Matrix): bool The system has a solution.
The example for this item is shown with the ones above: matrix-Solve.salam
func Cholesky (x &: Matrix): Matrix The Cholesky decomposition of a symmetric positive definite matrix, the L whose product with its transpose is A.
The example for this item is shown with the ones above: matrix-Solve.salam
func SolveSPD (a &: Matrix, b &: Matrix): Matrix Solves a symmetric positive definite system.
The example for this item is shown with the ones above: matrix-Solve.salam
func CholeskySolve (l &: Matrix, b &: Matrix): Matrix Solves it with a ready L.
The example for this item is shown with the ones above: matrix-Solve.salam
func InverseSPD (x &: Matrix): Matrix The inverse of a positive definite matrix.
The example for this item is shown with the ones above: matrix-Solve.salam
func DetSPD (x &: Matrix): f64 The determinant of a positive definite matrix.
The example for this item is shown with the ones above: matrix-Solve.salam
func LogDetSPD (x &: Matrix): f64 The logarithm of the determinant; for the multivariate normal distribution.
The example for this item is shown with the ones above: matrix-Solve.salam
func LDLDecompose (x &: Matrix): LDL The LDL decomposition of a symmetric matrix.
The example for this item is shown with the ones above: matrix-Solve.salam
func LDLSolve (f &: LDL, b &: Matrix): Matrix Solves it with the LDL decomposition.
The example for this item is shown with the ones above: matrix-Solve.salam
func Inertia (x &: Matrix): Matrix The number of positive, negative and zero eigenvalues.
The example for this item is shown with the ones above: matrix-Solve.salam
func Abs (x &: Matrix): Matrix The absolute value, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Sqrt (x &: Matrix): Matrix The square root, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Exp (x &: Matrix): Matrix The exponential, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Log (x &: Matrix): Matrix The natural logarithm, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Log10 (x &: Matrix): Matrix The base ten logarithm, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Log2 (x &: Matrix): Matrix The base two logarithm, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Sin (x &: Matrix): Matrix The sine, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Cos (x &: Matrix): Matrix The cosine, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Tan (x &: Matrix): Matrix The tangent, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Asin (x &: Matrix): Matrix The inverse sine, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Acos (x &: Matrix): Matrix The inverse cosine, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Atan (x &: Matrix): Matrix The inverse tangent, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Sinh (x &: Matrix): Matrix The hyperbolic sine, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Cosh (x &: Matrix): Matrix The hyperbolic cosine, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Tanh (x &: Matrix): Matrix The hyperbolic tangent, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Floor (x &: Matrix): Matrix The floor, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Ceil (x &: Matrix): Matrix The ceiling, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Round (x &: Matrix): Matrix Rounds to the nearest integer, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Trunc (x &: Matrix): Matrix Drops the fractional part, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Sign (x &: Matrix): Matrix The sign, meaning -1, 0 or 1, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Square (x &: Matrix): Matrix The square, element by element.
The example for this item is shown with the ones above: matrix-Create.salam
func Reciprocal (x &: Matrix): Matrix The reciprocal, one over the element, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func Cbrt (x &: Matrix): Matrix The cube root, negative numbers included, element by element.
The example for this item is shown with the ones above: matrix-Math.salam
func PowElem (x &: Matrix, p: f64 ): Matrix Raises the elements to a power.
The example for this item is shown with the ones above: matrix-Math.salam
func Clip (x &: Matrix, lo: f64 , hi: f64 ): Matrix Holds the elements within a range.
The example for this item is shown with the ones above: matrix-Math.salam
func MaxScalar (x &: Matrix, s: f64 ): Matrix The greater of each element and a number.
The example for this item is shown with the ones above: matrix-Math.salam
func MinScalar (x &: Matrix, s: f64 ): Matrix The smaller of each element and a number.
The example for this item is shown with the ones above: matrix-Math.salam
func Chop (x &: Matrix, tol: f64 ): Matrix Zeroes the elements smaller than a tolerance; for a clean display.
The example for this item is shown with the ones above: matrix-Math.salam
func IsSquare (x &: Matrix): bool The example for this item is shown with the ones above: matrix-Create.salam
func AllClose (x &: Matrix, y &: Matrix, tol: f64 ): bool The two matrices are equal within a tolerance.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsZero (x &: Matrix, tol: f64 ): bool The example for this item is shown with the ones above: matrix-Eigen.salam
func IsIdentity (x &: Matrix, tol: f64 ): bool The matrix is the identity.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsSymmetric (x &: Matrix, tol: f64 ): bool The example for this item is shown with the ones above: matrix-Eigen.salam
func IsSkewSymmetric (x &: Matrix, tol: f64 ): bool The matrix is skew symmetric.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsDiagonal (x &: Matrix, tol: f64 ): bool The example for this item is shown with the ones above: matrix-Solve.salam
func IsUpperTriangular (x &: Matrix, tol: f64 ): bool The matrix is upper triangular.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsLowerTriangular (x &: Matrix, tol: f64 ): bool The matrix is lower triangular.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsBanded (x &: Matrix, lower: int , upper: int , tol: f64 ): bool Every element sits within a band below and above the diagonal.
The example for this item is shown with the ones above: matrix-Eigen.salam
func LowerBandwidth (x &: Matrix, tol: f64 ): int The bandwidth below the diagonal.
The example for this item is shown with the ones above: matrix-Eigen.salam
func UpperBandwidth (x &: Matrix, tol: f64 ): int The bandwidth above the diagonal.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsOrthogonal (x &: Matrix, tol: f64 ): bool The matrix is orthogonal.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsNormal (x &: Matrix, tol: f64 ): bool The matrix is normal, meaning it commutes with its transpose.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsIdempotent (x &: Matrix, tol: f64 ): bool The matrix is idempotent, meaning its square is itself.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsInvolutory (x &: Matrix, tol: f64 ): bool The matrix is its own inverse.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsNilpotent (x &: Matrix, tol: f64 ): bool The example for this item is shown with the ones above: matrix-Eigen.salam
func IsPositiveDefinite (x &: Matrix, tol: f64 ): bool The matrix is positive definite.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsPositiveSemiDefinite (x &: Matrix, tol: f64 ): bool The matrix is positive semidefinite.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsSingular (x &: Matrix): bool The example for this item is shown with the ones above: matrix-Eigen.salam
func IsInvertible (x &: Matrix): bool The matrix is invertible.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsRowStochastic (x &: Matrix, tol: f64 ): bool The matrix is row stochastic, meaning every row sums to one.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsColStochastic (x &: Matrix, tol: f64 ): bool The matrix is column stochastic.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsDoublyStochastic (x &: Matrix, tol: f64 ): bool The matrix is doubly stochastic.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsPermutation (x &: Matrix, tol: f64 ): bool The matrix is a permutation matrix.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsToeplitz (x &: Matrix, tol: f64 ): bool The matrix is Toeplitz, meaning every diagonal is constant.
The example for this item is shown with the ones above: matrix-Eigen.salam
func IsHankel (x &: Matrix, tol: f64 ): bool The matrix is Hankel, meaning every antidiagonal is constant.
The example for this item is shown with the ones above: matrix-Eigen.salam
func Density (x &: Matrix): f64 The fraction of non zero elements.
The example for this item is shown with the ones above: matrix-Eigen.salam
func SVDecompose (x &: Matrix): SVD The singular value decomposition.
The example for this item is shown with the ones above: matrix-Eigen.salam
func SingularValues (x &: Matrix): Matrix The singular values alone.
The example for this item is shown with the ones above: matrix-Eigen.salam
func MatrixRank (x &: Matrix, tol: f64 ): int The rank, within a tolerance.
The example for this item is shown with the ones above: matrix-Solve.salam
func PseudoInverse (x &: Matrix, tol: f64 ): Matrix The Moore Penrose pseudoinverse.
The example for this item is shown with the ones above: matrix-Eigen.salam
func NullSpace (x &: Matrix, tol: f64 ): Matrix An orthogonal basis of the null space.
The example for this item is shown with the ones above: matrix-Solve.salam
func ColumnSpace (x &: Matrix, tol: f64 ): Matrix An orthogonal basis of the column space.
The example for this item is shown with the ones above: matrix-Solve.salam
func LowRankApprox (x &: Matrix, k: int ): Matrix The best rank k approximation; for compression.
The example for this item is shown with the ones above: matrix-Eigen.salam
func Expm (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Solve.salam
func Sqrtm (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Solve.salam
func MatrixSign (x &: Matrix): Matrix The matrix sign function.
The example for this item is shown with the ones above: matrix-Solve.salam
func PolyEval (x &: Matrix, coeffs &: Matrix): Matrix A polynomial with coefficients from degree zero, over a matrix.
The example for this item is shown with the ones above: matrix-Solve.salam
func CayleyHamilton (x &: Matrix): Matrix The characteristic polynomial over the matrix itself; by the theorem it is zero.
The example for this item is shown with the ones above: matrix-Solve.salam
func LogmSym (x &: Matrix): Matrix The matrix logarithm for a symmetric positive definite matrix.
The example for this item is shown with the ones above: matrix-Solve.salam
func HStack (x &: Matrix, y &: Matrix): Matrix Two matrices side by side.
matrix-Shape.salam Copy
import matrix
func build (rows: int , cols: int , numbers: str ): matrix.Matrix:
mut data := Vector {} as Vector < f64 >
each number in numbers. Split ( " " ):
data. Push (number. ToFloat ())
end
ret matrix. FromArray (rows, cols, data)
end
func show (name: str , m &: matrix.Matrix):
println name, matrix. ToRepr (m, 1 )
end
func main :
mut a := build ( 2 , 3 , "1 2 3 4 5 6" )
mut square := build ( 3 , 3 , "1 2 3 4 5 6 7 8 9" )
show ( "Reshape" , matrix. Reshape (a, 3 , 2 ))
show ( "Flatten" , matrix. Flatten (a))
show ( "FlattenCol" , matrix. FlattenCol (a))
mut row := matrix. Row (a, 1 )
mut col := matrix. Col (a, 2 )
show ( "Row" , row)
show ( "Col" , col)
mut b := matrix. Clone (a)
matrix. SetRow (b, 0 , row)
matrix. SetCol (b, 0 , col)
show ( "SetRow and SetCol" , b)
show ( "SubMatrix" , matrix. SubMatrix (square, 1 , 1 , 2 , 2 ))
show ( "Minor" , matrix. Minor (square, 0 , 0 ))
show ( "DeleteRow" , matrix. DeleteRow (square, 1 ))
show ( "DeleteCol" , matrix. DeleteCol (square, 1 ))
show ( "InsertRow" , matrix. InsertRow (a, 1 , matrix. Row (a, 0 )))
show ( "InsertCol" , matrix. InsertCol (a, 0 , matrix. Col (a, 2 )))
matrix. SwapRows (b, 0 , 1 )
matrix. SwapCols (b, 0 , 2 )
show ( "swapped" , b)
show ( "Diagonal" , matrix. Diagonal (square))
show ( "DiagonalOffset" , matrix. DiagonalOffset (square, 1 ))
mut c := matrix. Clone (square)
matrix. SetDiagonal (c, matrix. Ones ( 3 , 1 ))
matrix. ShiftDiagonal (c, 10.0 )
show ( "new diagonal" , matrix. Diagonal (c))
show ( "HStack" , matrix. HStack (a, a))
show ( "VStack" , matrix. VStack (a, a))
show ( "Augment" , matrix. Augment (square, matrix. Eye ( 3 )))
show ( "BlockDiag" , matrix. BlockDiag (matrix. Eye ( 1 ), matrix. Full ( 1 , 1 , 2.0 )))
show ( "Triu" , matrix. Triu (square, 0 ))
show ( "Tril" , matrix. Tril (square, - 1 ))
show ( "SymmetrizeUpper" , matrix. SymmetrizeUpper (square))
show ( "SymPart" , matrix. SymPart (square))
show ( "SkewPart" , matrix. SkewPart (square))
show ( "FlipVertical" , matrix. FlipVertical (a))
show ( "FlipHorizontal" , matrix. FlipHorizontal (a))
show ( "Rot90" , matrix. Rot90 (a, 1 ))
show ( "Roll" , matrix. Roll (a, 0 , 1 ))
show ( "Tile" , matrix. Tile (matrix. Eye ( 1 ), 2 , 2 ))
show ( "Pad" , matrix. Pad (matrix. Eye ( 1 ), 1 , 0 , 0 , 1 , 9.0 ))
end Output Reshape [1.0,2.0; 3.0,4.0; 5.0,6.0]
Flatten [1.0,2.0,3.0,4.0,5.0,6.0]
FlattenCol [1.0; 2.0; 3.0; 4.0; 5.0; 6.0]
Row [4.0,5.0,6.0]
Col [3.0; 6.0]
SetRow and SetCol [3.0,5.0,6.0; 6.0,5.0,6.0]
SubMatrix [5.0,6.0; 8.0,9.0]
Minor [5.0,6.0; 8.0,9.0]
DeleteRow [1.0,2.0,3.0; 7.0,8.0,9.0]
DeleteCol [1.0,3.0; 4.0,6.0; 7.0,9.0]
InsertRow [1.0,2.0,3.0; 1.0,2.0,3.0; 4.0,5.0,6.0]
InsertCol [3.0,1.0,2.0,3.0; 6.0,4.0,5.0,6.0]
swapped [6.0,5.0,6.0; 6.0,5.0,3.0]
Diagonal [1.0,5.0,9.0]
DiagonalOffset [2.0,6.0]
new diagonal [11.0,11.0,11.0]
HStack [1.0,2.0,3.0,1.0,2.0,3.0; 4.0,5.0,6.0,4.0,5.0,6.0]
VStack [1.0,2.0,3.0; 4.0,5.0,6.0; 1.0,2.0,3.0; 4.0,5.0,6.0]
Augment [1.0,2.0,3.0,1.0,0.0,0.0; 4.0,5.0,6.0,0.0,1.0,0.0; 7.0,8.0,9.0,0.0,0.0,1.0]
BlockDiag [1.0,0.0; 0.0,2.0]
Triu [1.0,2.0,3.0; 0.0,5.0,6.0; 0.0,0.0,9.0]
Tril [0.0,0.0,0.0; 4.0,0.0,0.0; 7.0,8.0,0.0]
SymmetrizeUpper [1.0,2.0,3.0; 2.0,5.0,6.0; 3.0,6.0,9.0]
SymPart [1.0,3.0,5.0; 3.0,5.0,7.0; 5.0,7.0,9.0]
SkewPart [0.0,-1.0,-2.0; 1.0,0.0,-1.0; 2.0,1.0,0.0]
FlipVertical [4.0,5.0,6.0; 1.0,2.0,3.0]
FlipHorizontal [3.0,2.0,1.0; 6.0,5.0,4.0]
Rot90 [3.0,6.0; 2.0,5.0; 1.0,4.0]
Roll [3.0,1.0,2.0; 6.0,4.0,5.0]
Tile [1.0,1.0; 1.0,1.0]
Pad [9.0,9.0; 1.0,9.0]
func VStack (x &: Matrix, y &: Matrix): Matrix Two matrices one above the other.
The example for this item is shown with the ones above: matrix-Shape.salam
func Augment (a &: Matrix, b &: Matrix): Matrix The augmented matrix, for solving a system.
The example for this item is shown with the ones above: matrix-Shape.salam
func BlockDiag (x &: Matrix, y &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Shape.salam
func Triu (x &: Matrix, k: int ): Matrix The part above diagonal k.
The example for this item is shown with the ones above: matrix-Shape.salam
func Tril (x &: Matrix, k: int ): Matrix The part below diagonal k.
The example for this item is shown with the ones above: matrix-Shape.salam
func SymmetrizeUpper (x &: Matrix): Matrix Mirrors the upper half into the lower.
The example for this item is shown with the ones above: matrix-Shape.salam
func SymPart (x &: Matrix): Matrix The symmetric part, half of A and its transpose.
The example for this item is shown with the ones above: matrix-Shape.salam
func SkewPart (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Shape.salam
func FlipVertical (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Shape.salam
func FlipHorizontal (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Shape.salam
func Rot90 (x &: Matrix, k: int ): Matrix k ninety degree turns anticlockwise.
The example for this item is shown with the ones above: matrix-Shape.salam
func Roll (x &: Matrix, dr: int , dc: int ): Matrix Rotates the rows and columns around.
The example for this item is shown with the ones above: matrix-Shape.salam
func Tile (x &: Matrix, ry: int , rx: int ): Matrix Repeats the matrix across rows and columns.
The example for this item is shown with the ones above: matrix-Shape.salam
func Pad (x &: Matrix, top: int , bottom: int , left: int , right: int , v: f64 ): Matrix Adds a border of a value around the matrix.
The example for this item is shown with the ones above: matrix-Shape.salam
func IsDiagonallyDominant (a &: Matrix): bool It is diagonally dominant; the Jacobi and Gauss Seidel methods then converge.
The example for this item is shown with the ones above: matrix-Solve.salam
func SolveJacobi (a &: Matrix, b &: Matrix, iters: int , tol: f64 ): IterResult The example for this item is shown with the ones above: matrix-Solve.salam
func SolveGaussSeidel (a &: Matrix, b &: Matrix, iters: int , tol: f64 ): IterResult The example for this item is shown with the ones above: matrix-Solve.salam
func SolveSOR (a &: Matrix, b &: Matrix, omega: f64 , iters: int , tol: f64 ): IterResult Successive over relaxation with a factor omega.
The example for this item is shown with the ones above: matrix-Solve.salam
func SolveCG (a &: Matrix, b &: Matrix, iters: int , tol: f64 ): IterResult Conjugate gradient for a symmetric positive definite matrix.
The example for this item is shown with the ones above: matrix-Solve.salam
func PowerIteration (a &: Matrix, iters: int ): Matrix Power iteration: the dominant eigenvector and, in the last element, its eigenvalue.
The example for this item is shown with the ones above: matrix-Eigen.salam
func Rayleigh (a &: Matrix, x &: Matrix): f64 The Rayleigh quotient; the eigenvalue estimate for a vector.
The example for this item is shown with the ones above: matrix-Eigen.salam
func ShiftedInverseIteration (a &: Matrix, shift: f64 , iters: int ): f64 The eigenvalue nearest the shift.
The example for this item is shown with the ones above: matrix-Eigen.salam
func EigSym (x &: Matrix): EigenSym The eigendecomposition of a symmetric matrix by the Jacobi method.
The example for this item is shown with the ones above: matrix-Eigen.salam
func EigValsSym (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Eigen.salam
func EigReconstruct (f &: EigenSym): Matrix Rebuilds the matrix from the eigenvectors and eigenvalues.
The example for this item is shown with the ones above: matrix-Eigen.salam
func SpectralRadiusSym (x &: Matrix): f64 The spectral radius of a symmetric matrix.
The example for this item is shown with the ones above: matrix-Eigen.salam
func PowSym (x &: Matrix, p: f64 ): Matrix A float power of a symmetric matrix.
The example for this item is shown with the ones above: matrix-Eigen.salam
func SqrtSym (x &: Matrix): Matrix The square root of a symmetric positive definite matrix.
The example for this item is shown with the ones above: matrix-Eigen.salam
func Decompose (x &: Matrix): LU The lower upper decomposition; for solving several systems with one matrix.
The example for this item is shown with the ones above: matrix-Solve.salam
func Det (x &: Matrix): f64 The example for this item is shown with the ones above: matrix-Solve.salam
func LogAbsDet (x &: Matrix): f64 The logarithm of the absolute determinant; without overflow.
The example for this item is shown with the ones above: matrix-Solve.salam
func Solve (a &: Matrix, b &: Matrix): Matrix Solves the system AX = B.
The example for this item is shown with the ones above: matrix-Solve.salam
func LUSolve (f &: LU, b &: Matrix): Matrix Solves it with a ready decomposition.
The example for this item is shown with the ones above: matrix-Solve.salam
func SolveVec (a &: Matrix, b &: Matrix): Matrix The system with one vector.
The example for this item is shown with the ones above: matrix-Solve.salam
func Inverse (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func Adjugate (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Solve.salam
func QRDecompose (x &: Matrix): QR The QR decomposition by Householder reflection.
The example for this item is shown with the ones above: matrix-Solve.salam
func QRGetQ (f &: QR): Matrix The example for this item is shown with the ones above: matrix-Solve.salam
func QRGetR (f &: QR): Matrix The upper triangular matrix R.
The example for this item is shown with the ones above: matrix-Solve.salam
func LeastSquares (a &: Matrix, b &: Matrix): Matrix The least squares solution of an overdetermined system; fitting a line, for instance.
The example for this item is shown with the ones above: matrix-Solve.salam
func QRSolve (f &: QR, b &: Matrix): Matrix Solves it with the QR decomposition.
The example for this item is shown with the ones above: matrix-Solve.salam
func Residual (a &: Matrix, x &: Matrix, b &: Matrix): Matrix The residual, AX minus B.
The example for this item is shown with the ones above: matrix-Solve.salam
func Orthonormalize (x &: Matrix): Matrix Makes the columns orthonormal.
The example for this item is shown with the ones above: matrix-Solve.salam
func Add (x &: Matrix, y &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func Sub (x &: Matrix, y &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func MulElem (x &: Matrix, y &: Matrix): Matrix Elementwise multiplication.
The example for this item is shown with the ones above: matrix-Math.salam
func DivElem (x &: Matrix, y &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func Neg (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func AddScalar (x &: Matrix, s: f64 ): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func SubScalar (x &: Matrix, s: f64 ): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func Scale (x &: Matrix, s: f64 ): Matrix Multiplication by a number.
The example for this item is shown with the ones above: matrix-Math.salam
func DivScalar (x &: Matrix, s: f64 ): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func AddInPlace (dst &: Matrix, src &: Matrix) The example for this item is shown with the ones above: matrix-Math.salam
func SubInPlace (dst &: Matrix, src &: Matrix) The example for this item is shown with the ones above: matrix-Math.salam
func MulElemInPlace (dst &: Matrix, src &: Matrix) Multiplies elementwise in place.
The example for this item is shown with the ones above: matrix-Math.salam
func ScaleInPlace (dst &: Matrix, s: f64 ) Multiplies by a number in place.
The example for this item is shown with the ones above: matrix-Math.salam
func AddScalarInPlace (dst &: Matrix, s: f64 ) The example for this item is shown with the ones above: matrix-Math.salam
func NegInPlace (dst &: Matrix) The example for this item is shown with the ones above: matrix-Math.salam
func AddScaled (dst &: Matrix, src &: Matrix, alpha: f64 ) Adds alpha times the source to the destination.
The example for this item is shown with the ones above: matrix-Math.salam
func Combine (x &: Matrix, a: f64 , y &: Matrix, b: f64 ): Matrix The linear combination a times x plus b times y.
The example for this item is shown with the ones above: matrix-Math.salam
func MaxElem (x &: Matrix, y &: Matrix): Matrix The elementwise greater of two matrices.
The example for this item is shown with the ones above: matrix-Math.salam
func MinElem (x &: Matrix, y &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func AddRowVector (x &: Matrix, row &: Matrix): Matrix Adds a row vector to every row.
The example for this item is shown with the ones above: matrix-Math.salam
func AddColVector (x &: Matrix, col &: Matrix): Matrix Adds a column vector to every column.
The example for this item is shown with the ones above: matrix-Math.salam
func MulRowVector (x &: Matrix, row &: Matrix): Matrix Multiplies every row elementwise by a row vector.
The example for this item is shown with the ones above: matrix-Math.salam
func MulColVector (x &: Matrix, col &: Matrix): Matrix Multiplies every column by a column vector.
The example for this item is shown with the ones above: matrix-Math.salam
func CenterColumns (x &: Matrix): Matrix Subtracts the mean of each column.
The example for this item is shown with the ones above: matrix-Stats.salam
func ColumnMeans (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Stats.salam
func ColumnStds (x &: Matrix, sample: bool ): Matrix The standard deviation of each column.
The example for this item is shown with the ones above: matrix-Stats.salam
func Standardize (x &: Matrix, sample: bool ): Matrix Every column with mean zero and standard deviation one.
The example for this item is shown with the ones above: matrix-Stats.salam
func Covariance (x &: Matrix, sample: bool ): Matrix The covariance matrix of the columns.
The example for this item is shown with the ones above: matrix-Stats.salam
func Correlation (x &: Matrix): Matrix The Pearson correlation matrix.
The example for this item is shown with the ones above: matrix-Stats.salam
func PCAFit (x &: Matrix): PCA Principal component analysis through the covariance.
The example for this item is shown with the ones above: matrix-Stats.salam
func PCAFromSVD (x &: Matrix): PCA The same, through the singular value decomposition; more stable.
The example for this item is shown with the ones above: matrix-Stats.salam
func PCATransform (p &: PCA, x &: Matrix, k: int ): Matrix Projects the data onto the first k components.
The example for this item is shown with the ones above: matrix-Stats.salam
func ExplainedVariance (p &: PCA): Matrix The share each component takes of the total variance.
The example for this item is shown with the ones above: matrix-Stats.salam
func LinearRegression (x &: Matrix, y &: Matrix): Matrix The coefficients of a linear regression; a column of ones is added for the intercept.
The example for this item is shown with the ones above: matrix-Stats.salam
func RSquared (y &: Matrix, fitted &: Matrix): f64 The coefficient of determination.
The example for this item is shown with the ones above: matrix-Stats.salam
func Reshape (x &: Matrix, rows: int , cols: int ): Matrix The example for this item is shown with the ones above: matrix-Shape.salam
func Flatten (x &: Matrix): Matrix A row vector of every element.
The example for this item is shown with the ones above: matrix-Shape.salam
func FlattenCol (x &: Matrix): Matrix A column vector, column by column.
The example for this item is shown with the ones above: matrix-Shape.salam
func Row (x &: Matrix, i: int ): Matrix The example for this item is shown with the ones above: matrix-Shape.salam
func Col (x &: Matrix, j: int ): Matrix Column j as a column vector.
The example for this item is shown with the ones above: matrix-Shape.salam
func SetRow (x &: Matrix, i: int , v &: Matrix) The example for this item is shown with the ones above: matrix-Shape.salam
func SetCol (x &: Matrix, j: int , v &: Matrix) The example for this item is shown with the ones above: matrix-Shape.salam
func SubMatrix (x &: Matrix, r0: int , c0: int , dr: int , dc: int ): Matrix A submatrix from a starting row and column, with a size.
The example for this item is shown with the ones above: matrix-Shape.salam
func Minor (x &: Matrix, i: int , j: int ): Matrix The matrix without row i and column j.
The example for this item is shown with the ones above: matrix-Shape.salam
func DeleteRow (x &: Matrix, i: int ): Matrix The example for this item is shown with the ones above: matrix-Shape.salam
func DeleteCol (x &: Matrix, j: int ): Matrix The example for this item is shown with the ones above: matrix-Shape.salam
func InsertRow (x &: Matrix, i: int , v &: Matrix): Matrix With a new row at place i.
The example for this item is shown with the ones above: matrix-Shape.salam
func InsertCol (x &: Matrix, j: int , v &: Matrix): Matrix With a new column at place j.
The example for this item is shown with the ones above: matrix-Shape.salam
func SwapRows (x &: Matrix, i: int , j: int ) The example for this item is shown with the ones above: matrix-Shape.salam
func SwapCols (x &: Matrix, i: int , j: int ) Swaps two columns in place.
The example for this item is shown with the ones above: matrix-Shape.salam
func Diagonal (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Shape.salam
func DiagonalOffset (x &: Matrix, k: int ): Matrix The kth diagonal; positive is above the main one.
The example for this item is shown with the ones above: matrix-Shape.salam
func SetDiagonal (x &: Matrix, v &: Matrix) The example for this item is shown with the ones above: matrix-Shape.salam
func ShiftDiagonal (x &: Matrix, c: f64 ) Adds a number to the diagonal.
The example for this item is shown with the ones above: matrix-Shape.salam
func ToStringPrec (x &: Matrix, prec: int ): str Multi line text with a number of decimal places.
The example for this item is shown with the ones above: matrix-Create.salam
func ToString (x &: Matrix): str The example for this item is shown with the ones above: matrix-Create.salam
func ShapeString (x &: Matrix): str The example for this item is shown with the ones above: matrix-Create.salam
The example for this item is shown with the ones above: matrix-Create.salam
func PrintPrec (x &: Matrix, prec: int ) Prints it with a number of decimal places.
The example for this item is shown with the ones above: matrix-Create.salam
func PrintLabeled (label: str , x &: Matrix) Prints it with a label and its shape.
The example for this item is shown with the ones above: matrix-Create.salam
func ToCSV (x &: Matrix, prec: int ): str The example for this item is shown with the ones above: matrix-Create.salam
func ToRepr (x &: Matrix, prec: int ): str One line text such as [1,2; 3,4].
The example for this item is shown with the ones above: matrix-Create.salam
func Sum (x &: Matrix): f64 The example for this item is shown with the ones above: matrix-Math.salam
func Prod (x &: Matrix): f64 The product of everything.
The example for this item is shown with the ones above: matrix-Math.salam
func Mean (x &: Matrix): f64 The example for this item is shown with the ones above: matrix-Math.salam
func Min (x &: Matrix): f64 The example for this item is shown with the ones above: matrix-Create.salam
func Max (x &: Matrix): f64 The example for this item is shown with the ones above: matrix-Math.salam
func Range (x &: Matrix): f64 The greatest minus the smallest.
The example for this item is shown with the ones above: matrix-Math.salam
func ArgMin (x &: Matrix): int Where the minimum is, in row order.
The example for this item is shown with the ones above: matrix-Math.salam
func ArgMax (x &: Matrix): int The example for this item is shown with the ones above: matrix-Math.salam
func IndexRow (x &: Matrix, k: int ): int The row of place k in row order.
The example for this item is shown with the ones above: matrix-Math.salam
func IndexCol (x &: Matrix, k: int ): int The example for this item is shown with the ones above: matrix-Math.salam
func MaxAbs (x &: Matrix): f64 The greatest absolute value.
The example for this item is shown with the ones above: matrix-Math.salam
func Var (x &: Matrix, sample: bool ): f64 The variance; the sample one with sample.
The example for this item is shown with the ones above: matrix-Math.salam
func Std (x &: Matrix, sample: bool ): f64 The example for this item is shown with the ones above: matrix-Math.salam
func Median (x &: Matrix): f64 The example for this item is shown with the ones above: matrix-Math.salam
func RowSums (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func ColSums (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func RowMeans (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func ColMeans (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Math.salam
func RowMins (x &: Matrix): Matrix The smallest of each row.
The example for this item is shown with the ones above: matrix-Math.salam
func RowMaxs (x &: Matrix): Matrix The greatest of each row.
The example for this item is shown with the ones above: matrix-Math.salam
func ColMins (x &: Matrix): Matrix The smallest of each column.
The example for this item is shown with the ones above: matrix-Math.salam
func ColMaxs (x &: Matrix): Matrix The greatest of each column.
The example for this item is shown with the ones above: matrix-Math.salam
func CumSumRows (x &: Matrix): Matrix The cumulative sum along each row.
The example for this item is shown with the ones above: matrix-Math.salam
func CumSumCols (x &: Matrix): Matrix The cumulative sum along each column.
The example for this item is shown with the ones above: matrix-Math.salam
func CumProdRows (x &: Matrix): Matrix The cumulative product along each row.
The example for this item is shown with the ones above: matrix-Math.salam
func CountNonZero (x &: Matrix): int The number of non zero elements.
The example for this item is shown with the ones above: matrix-Math.salam
func Any (x &: Matrix): bool At least one element is non zero.
The example for this item is shown with the ones above: matrix-Create.salam
func All (x &: Matrix): bool Every element is non zero.
The example for this item is shown with the ones above: matrix-Create.salam
func AllFinite (x &: Matrix): bool No element is NaN or infinite.
The example for this item is shown with the ones above: matrix-Math.salam
func NormFrobenius (x &: Matrix): f64 The Frobenius norm, the square root of the sum of the squares.
The example for this item is shown with the ones above: matrix-Math.salam
func Norm1 (x &: Matrix): f64 The one norm, the greatest absolute column sum.
The example for this item is shown with the ones above: matrix-Math.salam
func NormInf (x &: Matrix): f64 The infinity norm, the greatest absolute row sum.
The example for this item is shown with the ones above: matrix-Math.salam
func NormMax (x &: Matrix): f64 The greatest absolute element.
The example for this item is shown with the ones above: matrix-Math.salam
func Norm2 (x &: Matrix): f64 The two norm, the largest singular value.
The example for this item is shown with the ones above: matrix-Math.salam
func NormNuclear (x &: Matrix): f64 The nuclear norm, the sum of the singular values.
The example for this item is shown with the ones above: matrix-Math.salam
func VecNorm (x &: Matrix, p: f64 ): f64 The example for this item is shown with the ones above: matrix-Math.salam
func Distance (x &: Matrix, y &: Matrix): f64 The example for this item is shown with the ones above: matrix-Math.salam
func Normalize (x &: Matrix): Matrix The vector scaled to length one.
The example for this item is shown with the ones above: matrix-Math.salam
func NormalizeRows (x &: Matrix): Matrix Every row scaled to length one.
The example for this item is shown with the ones above: matrix-Math.salam
func NormalizeCols (x &: Matrix): Matrix Every column scaled to length one.
The example for this item is shown with the ones above: matrix-Math.salam
func Cond1 (x &: Matrix): f64 The condition number in the one norm.
The example for this item is shown with the ones above: matrix-Math.salam
func CondInf (x &: Matrix): f64 The condition number in the infinity norm.
The example for this item is shown with the ones above: matrix-Math.salam
func Cond2 (x &: Matrix): f64 The condition number in the two norm; a large one means solving the system is unstable.
The example for this item is shown with the ones above: matrix-Math.salam
func Zeros (rows: int , cols: int ): Matrix The example for this item is shown with the ones above: matrix-Create.salam
func Ones (rows: int , cols: int ): Matrix The example for this item is shown with the ones above: matrix-Create.salam
func Full (rows: int , cols: int , x: f64 ): Matrix A matrix filled with one value.
The example for this item is shown with the ones above: matrix-Create.salam
The n by n identity matrix.
The example for this item is shown with the ones above: matrix-Create.salam
func EyeOffset (rows: int , cols: int , k: int ): Matrix Ones on the kth diagonal.
The example for this item is shown with the ones above: matrix-Create.salam
func FromArray (rows: int , cols: int , data &: Vector < f64 >): Matrix A matrix from a row count, a column count and the data in row order.
The example for this item is shown with the ones above: matrix-Create.salam
func RowVector (data &: Vector < f64 >): Matrix The example for this item is shown with the ones above: matrix-Create.salam
func ColVector (data &: Vector < f64 >): Matrix The example for this item is shown with the ones above: matrix-Create.salam
func Diag (data &: Vector < f64 >): Matrix A diagonal matrix from a set of values.
The example for this item is shown with the ones above: matrix-Create.salam
func Clone (x &: Matrix): Matrix The example for this item is shown with the ones above: matrix-Create.salam
func CopyInto (dst &: Matrix, src &: Matrix) Copies the data into a matrix of the same shape.
The example for this item is shown with the ones above: matrix-Create.salam
The example for this item is shown with the ones above: matrix-Create.salam
func SetAll (x &: Matrix, v: f64 ) Sets everything to one value.
The example for this item is shown with the ones above: matrix-Create.salam
func Arange (start: f64 , stop: f64 , step: f64 ): Matrix A row vector from the start up to but not including the end, by a step.
The example for this item is shown with the ones above: matrix-Create.salam
func Linspace (start: f64 , stop: f64 , num: int ): Matrix n evenly spaced numbers from the start to the end.
The example for this item is shown with the ones above: matrix-Create.salam
func Logspace (start: f64 , stop: f64 , num: int , base: f64 ): Matrix n logarithmically spaced numbers; from the base to the power of the start to the base to the power of the end.
The example for this item is shown with the ones above: matrix-Create.salam