ReadonlycolumnsNumber of columns of the matrix.
Readonlydiagonalalias for rows or columns (square matrix so equals)
ReadonlyrowsNumber of rows of the matrix.
ReadonlysizeTotal number of elements in the matrix.
iterator from left to right, from top to bottom yield [row, column, value]
Adds the values of a vector to each column.
Array or vector.
Symmetric add row / column
Adds the values of a vector to each row.
Array or vector.
Applies a callback for each element of the matrix. The function is called in the matrix (this) context.
Function that will be called for each element in the matrix.
remove sides (rows / columns) with falsy value from mask.
Center the matrix in-place. By default, the mean value of the matrix is subtracted from every value.
Optionaloptions: ICenterOptionsCenter the matrix in-place. By default, the mean values in the give dimension are subtracted from the values.
center by 'row' or 'column'.
Optionaloptions: ICenterByOptionsCreates an exact and independent copy of the matrix.
Computes the cumulative sum of the matrix elements (in place, row by row).
Returns an array containing the diagonal values of the matrix.
Alias for AbstractMatrix.diag.
Divides the values of each column by those of a vector.
Array or vector.
Divides the values of each row by those of a vector.
Array or vector.
Computes the dot (scalar) product between the matrix and another.
Returns the row echelon form of the matrix computed using gaussian elimination.
iterator from left to right, from top to bottom yield [row, column, value]
Fills the matrix with a given value. All elements will be set to this value.
New value.
Returns the value of the given element of the matrix.
Index of the element's row.
Index of the element's column.
Returns a new array with the values from the given column index.
Column index.
Returns a new column vector with the values from the given column index.
Column index.
Returns a new array with the values from the given row index.
Row index.
Returns a new row vector with the values from the given row index.
Row index.
Returns the Gram matrix thisᵀ · this (the columns × columns matrix of
the dot products of every pair of columns). The result is symmetric, so only
its upper triangle is computed and mirrored, and the transpose is never
materialized, making it about twice as fast as this.transpose().mmul(this)
on dense matrices and much faster on sparse ones (zero entries are skipped).
For finite inputs the result is identical to this.transpose().mmul(this).
Returns whether the matrix has one column.
Returns whether the matrix is symmetric and diagonal values are equals to 0
Returns whether the matrix is in row echelon form.
Returns whether the number of rows or columns (or both) is zero.
Returns whether the matrix is in reduced row echelon form.
Returns whether the matrix has one row.
Returns whether the matrix has the same number of rows and columns.
Returns whether the matrix is square and has the same values on both sides of the diagonal.
Returns whether the matrix has one row or one column.
Returns the Kronecker product (also known as tensor product) between this and other.
Other matrix.
Returns the Kronecker sum between this and other.
Other matrix.
Returns the maximum value of the matrix.
Returns the maximum value by the given dimension.
max by 'row' or 'column'.
Returns the maximum value of one column.
Column index.
Returns the index of the maximum value of one column.
Column index.
Returns the index of the maximum value.
Returns the maximum value of one row.
Row index.
Returns the index of the maximum value of one row.
Row index.
Returns the mean of all elements of the matrix.
Returns the mean by the given dimension.
mean by 'row' or 'column'.
Returns the minimum value of the matrix.
Returns the minimum value by the given dimension.
min by 'row' or 'column'.
Returns the minimum value of one column.
Column index.
Returns the index of the minimum value of one column.
Column index.
Returns the index of the minimum value.
Returns the minimum value of one row.
Row index.
Returns the index of the maximum value of one row.
Row index.
Returns the matrix product between this and other.
Other matrix.
Returns the matrix product between this and its transpose (this · thisᵀ),
optionally weighting each column by scale (this · diag(scale) · thisᵀ).
The result is symmetric, so only its upper triangle is computed and mirrored
and the transpose is never materialized, making it about twice as fast as
this.mmul(this.transpose()).
Optionalscale: ArrayLike<number>Optional per-column factors (length equal to the number of columns).
Returns the square matrix raised to the given power
the non-negative integer power to raise this matrix to
Multiplies the values of a column with a scalar.
Column index.
Multiplies the values of a vector with each column.
Array or vector.
Multiplies the values of a row with a scalar.
Row index.
Multiplies the values of a vector with each row.
Array or vector.
Negates the matrix. All elements will be multiplied by -1.
Alias for AbstractMatrix.neg.
Returns the norm of a matrix.
Optionaltype: "max" | "frobenius"Norm type. Default: 'frobenius'.
Returns the product of all elements of the matrix.
Returns the product by the given dimension.
product by 'row' or 'column'.
Returns the reduced row echelon form of the matrix computed using gaussian elimination.
Symmetric remove row / column
Creates a new matrix that is a repetition of the current matrix. New matrix has rows times the number of rows of the original matrix, and columns times the number of columns of the original matrix.
Optionaloptions: IRepeatOptionsScale the matrix in-place. By default, values are divided by their standard deviation.
Optionaloptions: IScaleOptionsScale the matrix in-place. By default, values are divided by the standard deviation in the given dimension.
scale by 'row' or 'column'.
Optionaloptions: IScaleByOptionsReturns a new column-by-column scaled matrix.
Optionaloptions: IScaleOptionsReturn a new matrix based on a selection of rows and columns. Order of the indices matters and the same index can be used more than once.
The row indices to select.
The column indices to select.
because it's a distance matrix, if rowIndex === columnIndex, value will be set to 0
Sets a column at the given index.
Column index.
Array or vector to set.
Sets a row at the given index.
Row index.
Array or vector to set.
Set a part of the matrix to the given sub-matrix.
The source matrix from which to extract values.
The index of the first row to set.
The index of the first column to set.
Sorts the columns in-place.
OptionalcompareFunction: (a: number, b: number) => numberSorts the rows in-place.
OptionalcompareFunction: (a: number, b: number) => numberReturns the standard deviation of all elements of the matrix.
Optionaloptions: IVarianceOptionsReturns the standard deviation by the given dimension.
standard deviation by 'row' or 'column'.
Optionaloptions: IVarianceByOptionsSubtracts the values of a vector from each column.
Array or vector.
Returns a subset of the matrix.
First row index.
Last row index.
First column index.
Last column index.
Returns a subset of the matrix based on an array of column indices.
Array containing the column indices.
OptionalstartRow: numberFirst row index. Default: 0.
OptionalendRow: numberLast row index. Default: this.rows - 1.
Returns a subset of the matrix based on an array of row indices.
Array containing the row indices.
OptionalstartColumn: numberFirst column index. Default: 0.
OptionalendColumn: numberLast column index. Default: this.columns - 1.
Subtracts the values of a vector from each row.
Array or vector.
Returns the sum of all elements of the matrix.
Returns the sum by the given dimension.
sum by 'row' or 'column'.
Swap two columns.
First column index.
Second column index.
Swap two rows.
First row index.
Second row index.
Returns a new 1D array filled row by row with the matrix values.
Returns a 2D array containing a copy of the matrix data.
Compact format upper-right corner of matrix no diagonal (because only store zeros) iterable from left to right, from top to bottom.
A B C D
A 0 1 2 3
B 1 0 4 5
C 2 4 0 6
D 3 5 6 0
will return compact 1D array [1, 2, 3, 4, 5, 6]
length is S(i=0, n=sideSize-1) => 6 for a 4 side sized matrix
copy to a new matrix
Optionaloptions: IToStringOptionsReturns the trace of the matrix (sum of the diagonal elements).
Transposes the matrix and returns a new one containing the result.
half iterator upper-right-corner from left to right, from top to bottom yield [row, column, value]
half iterator upper-right-corner from left to right, from top to bottom yield value
iterator from left to right, from top to bottom yield value
Returns the variance of all elements of the matrix.
Optionaloptions: IVarianceOptionsReturns the variance by the given dimension.
variance by 'row' or 'column'.
Optionaloptions: IVarianceByOptionsStaticabsStaticacosStaticacoshStaticaddStaticandStaticasinStaticasinhStaticatanStaticatanhStaticcbrtStaticceilStaticcheckCheck that the provided value is a Matrix and tries to instantiate one if not.
The value to check.
Staticclz32StaticcolumnCreates a column vector, a matrix with only one column.
A 1D array containing data for the vector.
The new matrix.
StaticcopyStaticcosStaticcoshStaticdiagCreates a diagonal matrix based on the given array.
Array containing the data for the diagonal.
Optionalrows: numberNumber of rows. Default: data.length.
Optionalcolumns: numberNumber of columns. Default: rows.
StaticdiagonalAlias for AbstractMatrix.diag.
Optionalrows: numberOptionalcolumns: numberStaticdivStaticdivideStaticexpStaticexpm1StaticeyeCreates an identity matrix with the given dimension. Values of the diagonal will be 1 and others will be 0.
Number of rows.
Optionalcolumns: numberNumber of columns. Default: rows.
Optionalvalue: numberValue to fill the diagonal with. Default: 1.
StaticfloorStaticfrom1Constructs a matrix with the chosen dimensions from a 1D array.
Number of rows.
Number of columns.
A 1D array containing data for the matrix.
The new matrix.
StaticfromStaticfroundStaticidentityAlias for AbstractMatrix.eye.
Optionalcolumns: numberOptionalvalue: numberStaticisStaticisReturns whether value is a Matrix.
The value to check.
StaticisStaticleftStaticlogStaticlog10Staticlog1pStaticlog2StaticmaxReturns a matrix whose elements are the maximum between matrix1 and matrix2.
StaticminReturns a matrix whose elements are the minimum between matrix1 and matrix2.
StaticmodStaticmodulusStaticmulStaticmultiplyStaticnotStaticonesCreates a symmetric matrix with the given dimensions. Values will be set to one.
is private, do not specify it
Number of rows or columns (square).
The new symmetric matrix.
StaticorStaticpowStaticrandCreates a matrix with the given dimensions. Values will be randomly set.
Number of rows.
Number of columns.
Optionaloptions: IRandomOptionsOptions object.
The new matrix.
StaticrandCreates a matrix with the given dimensions. Values will be random integers.
Number of rows.
Number of columns.
Optionaloptions: IRandomIntOptionsStaticrandomOptionaloptions: IRandomOptionsStaticrightStaticroundStaticrowCreates a row vector, a matrix with only one row.
A 1D array containing data for the vector.
The new matrix.
StaticsignStaticsignStaticsinStaticsinhStaticsqrtStaticsubStaticsubtractStatictanStatictanhStatictruncStaticxorStaticzeroStaticzerosCreates a distance matrix with the given dimensions. Values will be set to zero. This is equivalent to calling the Matrix constructor.
is private, do not specify it
Number of rows or columns (square).
The new symmetric matrix.
Throws
TypeError if data are not symmetric and diagonal is not 0