Class AbstractMatrixAbstract

Hierarchy (View Summary)

Constructors

Properties

Methods

[iterator] abs acos acosh add addColumnVector addRowVector and apply asin asinh atan atanh cbrt ceil center clone clz32 cos cosh cumulativeSum diag diagonal div divColumnVector divide divRowVector dot echelonForm entries exp expm1 fill flipColumns flipRows floor fround get getColumn getColumnVector getRow getRowVector isColumnVector isDistance isEchelonForm isEmpty isReducedEchelonForm isRowVector isSquare isSymmetric isVector kroneckerProduct kroneckerSum leftShift log log10 log1p log2 max maxColumn maxColumnIndex maxIndex maxRow maxRowIndex mean min minColumn minColumnIndex minIndex minRow minRowIndex mmul mmulStrassen mod modulus mpow mul mulColumn mulColumnVector mulRow mulRowVector multiply neg negate norm not or pow product reducedEchelonForm repeat rightShift round scale scaleColumns scaleRows selection set setColumn setRow setSubMatrix sign signPropagatingRightShift sin sinh sortColumns sortRows sqrt standardDeviation strassen2x2 strassen3x3 sub subColumnVector subMatrix subMatrixColumn subMatrixRow subRowVector subtract sum swapColumns swapRows tan tanh tensorProduct to1DArray to2DArray toJSON toString trace transpose trunc values variance xor zeroFillRightShift abs acos acosh add and asin asinh atan atanh cbrt ceil checkMatrix clz32 columnVector copy cos cosh diag diagonal div divide exp expm1 eye floor from1DArray fround identity isMatrix leftShift log log10 log1p log2 max min mod modulus mul multiply not ones or pow rand randInt random rightShift round rowVector sign signPropagatingRightShift sin sinh sqrt sub subtract tan tanh trunc xor zeroFillRightShift zeros

Constructors

Properties

columns: number

Number of columns of the matrix.

rows: number

Number of rows of the matrix.

size: number

Total number of elements in the matrix.

Methods

  • iterator from left to right, from top to bottom yield [row, column, value]

    Returns Generator<[row: number, column: number, value: number], void, void>

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Adds the values of a vector to each column.

    Parameters

    Returns this

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Applies a callback for each element of the matrix. The function is called in the matrix (this) context.

    Parameters

    • callback: (row: number, column: number) => void

      Function that will be called for each element in the matrix.

    Returns this

  • Center the matrix in-place. By default, the mean value of the matrix is subtracted from every value.

    Parameters

    Returns this

  • Center the matrix in-place. By default, the mean values in the give dimension are subtracted from the values.

    Parameters

    • by: MatrixDimension

      center by 'row' or 'column'.

    • Optionaloptions: ICenterByOptions

    Returns this

  • Creates an exact and independent copy of the matrix.

    Returns this

  • Computes the cumulative sum of the matrix elements (in place, row by row).

    Returns this

  • Returns an array containing the diagonal values of the matrix.

    Returns number[]

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Divides the values of each column by those of a vector.

    Parameters

    Returns this

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Divides the values of each row by those of a vector.

    Parameters

    Returns this

  • Returns the row echelon form of the matrix computed using gaussian elimination.

    Returns Matrix

  • iterator from left to right, from top to bottom yield [row, column, value]

    Returns Generator<[row: number, column: number, value: number], void, void>

  • Fills the matrix with a given value. All elements will be set to this value.

    Parameters

    • value: number

      New value.

    Returns this

  • Returns the value of the given element of the matrix.

    Parameters

    • rowIndex: number

      Index of the element's row.

    • columnIndex: number

      Index of the element's column.

    Returns number

    • The value of the element.
  • Returns a new array with the values from the given column index.

    Parameters

    • index: number

      Column index.

    Returns number[]

  • Returns a new column vector with the values from the given column index.

    Parameters

    • index: number

      Column index.

    Returns Matrix

  • Returns a new array with the values from the given row index.

    Parameters

    • index: number

      Row index.

    Returns number[]

  • Returns a new row vector with the values from the given row index.

    Parameters

    • index: number

      Row index.

    Returns Matrix

  • Returns whether the matrix has one column.

    Returns boolean

  • Returns whether the matrix is symmetric and diagonal values are equals to 0

    Returns boolean

  • Returns whether the matrix is in row echelon form.

    Returns boolean

  • Returns whether the number of rows or columns (or both) is zero.

    Returns boolean

  • Returns whether the matrix is in reduced row echelon form.

    Returns boolean

  • Returns whether the matrix has one row.

    Returns boolean

  • Returns whether the matrix has the same number of rows and columns.

    Returns boolean

  • Returns whether the matrix is square and has the same values on both sides of the diagonal.

    Returns boolean

  • Returns whether the matrix has one row or one column.

    Returns boolean

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Returns the maximum value of the matrix.

    Returns number

  • Returns the maximum value by the given dimension.

    Parameters

    • by: MatrixDimension

      max by 'row' or 'column'.

    Returns number[]

  • Returns the maximum value of one column.

    Parameters

    • column: number

      Column index.

    Returns number

  • Returns the index of the maximum value of one column.

    Parameters

    • column: number

      Column index.

    Returns [number, number]

  • Returns the index of the maximum value.

    Returns [number, number]

  • Returns the maximum value of one row.

    Parameters

    • row: number

      Row index.

    Returns number

  • Returns the index of the maximum value of one row.

    Parameters

    • row: number

      Row index.

    Returns [number, number]

  • Returns the mean of all elements of the matrix.

    Returns number

  • Returns the mean by the given dimension.

    Parameters

    • by: MatrixDimension

      mean by 'row' or 'column'.

    Returns number[]

  • Returns the minimum value of the matrix.

    Returns number

  • Returns the minimum value by the given dimension.

    Parameters

    • by: MatrixDimension

      min by 'row' or 'column'.

    Returns number[]

  • Returns the minimum value of one column.

    Parameters

    • column: number

      Column index.

    Returns number

  • Returns the index of the minimum value of one column.

    Parameters

    • column: number

      Column index.

    Returns [number, number]

  • Returns the index of the minimum value.

    Returns [number, number]

  • Returns the minimum value of one row.

    Parameters

    • row: number

      Row index.

    Returns number

  • Returns the index of the maximum value of one row.

    Parameters

    • row: number

      Row index.

    Returns [number, number]

  • Returns the matrix product between this and other.

    Parameters

    • other: MaybeMatrix

      Other matrix.

    Returns Matrix

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Returns the square matrix raised to the given power

    Parameters

    • scalar: number

      the non-negative integer power to raise this matrix to

    Returns Matrix

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Multiplies the values of a column with a scalar.

    Parameters

    • index: number

      Column index.

    • value: number

    Returns this

  • Multiplies the values of a vector with each column.

    Parameters

    Returns this

  • Multiplies the values of a row with a scalar.

    Parameters

    • index: number

      Row index.

    • value: number

    Returns this

  • Multiplies the values of a vector with each row.

    Parameters

    Returns this

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Negates the matrix. All elements will be multiplied by -1.

    Returns this

  • Returns the norm of a matrix.

    Parameters

    • Optionaltype: "max" | "frobenius"

      Norm type. Default: 'frobenius'.

    Returns number

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Returns the product of all elements of the matrix.

    Returns number

  • Returns the product by the given dimension.

    Parameters

    • by: MatrixDimension

      product by 'row' or 'column'.

    Returns number[]

  • Returns the reduced row echelon form of the matrix computed using gaussian elimination.

    Returns Matrix

  • 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.

    Parameters

    Returns Matrix

    var matrix = new Matrix([[1, 2]]);
    matrix.repeat({ rows: 2 }); // [[1, 2], [1, 2]]
  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Scale the matrix in-place. By default, values are divided by their standard deviation.

    Parameters

    Returns this

  • Scale the matrix in-place. By default, values are divided by the standard deviation in the given dimension.

    Parameters

    • by: MatrixDimension

      scale by 'row' or 'column'.

    • Optionaloptions: IScaleByOptions

    Returns this

  • Returns a new column-by-column scaled matrix.

    Parameters

    Returns Matrix

    var matrix = new Matrix([[1, 2], [-1, 0]]);
    var scaledMatrix = matrix.scaleColumns(); // [[1, 1], [0, 0]]
  • Return 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.

    Parameters

    • rowIndices: ArrayLike<number>

      The row indices to select.

    • columnIndices: ArrayLike<number>

      The column indices to select.

    Returns Matrix

  • Sets a given element of the matrix.

    Parameters

    • rowIndex: number

      Index of the element's row.

    • columnIndex: number

      Index of the element's column.

    • value: number

      The new value for the element.

    Returns this

  • Sets a column at the given index.

    Parameters

    • index: number

      Column index.

    • array: ArrayLike<number> | AbstractMatrix

      Array or vector to set.

    Returns this

  • Sets a row at the given index.

    Parameters

    • index: number

      Row index.

    • array: ArrayLike<number> | AbstractMatrix

      Array or vector to set.

    Returns this

  • Set a part of the matrix to the given sub-matrix.

    Parameters

    • matrix: MaybeMatrix

      The source matrix from which to extract values.

    • startRow: number

      The index of the first row to set.

    • startColumn: number

      The index of the first column to set.

    Returns this

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Sorts the columns in-place.

    Parameters

    • OptionalcompareFunction: (a: number, b: number) => number

    Returns this

  • Sorts the rows in-place.

    Parameters

    • OptionalcompareFunction: (a: number, b: number) => number

    Returns this

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Subtracts the values of a vector from each column.

    Parameters

    Returns this

  • Returns a subset of the matrix.

    Parameters

    • startRow: number

      First row index.

    • endRow: number

      Last row index.

    • startColumn: number

      First column index.

    • endColumn: number

      Last column index.

    Returns Matrix

  • Returns a subset of the matrix based on an array of column indices.

    Parameters

    • indices: ArrayLike<number>

      Array containing the column indices.

    • OptionalstartRow: number

      First row index. Default: 0.

    • OptionalendRow: number

      Last row index. Default: this.rows - 1.

    Returns Matrix

  • Returns a subset of the matrix based on an array of row indices.

    Parameters

    • indices: ArrayLike<number>

      Array containing the row indices.

    • OptionalstartColumn: number

      First column index. Default: 0.

    • OptionalendColumn: number

      Last column index. Default: this.columns - 1.

    Returns Matrix

  • Subtracts the values of a vector from each row.

    Parameters

    Returns this

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Returns the sum of all elements of the matrix.

    Returns number

  • Returns the sum by the given dimension.

    Parameters

    • by: MatrixDimension

      sum by 'row' or 'column'.

    Returns number[]

  • Swap two columns.

    Parameters

    • column1: number

      First column index.

    • column2: number

      Second column index.

    Returns this

  • Swap two rows.

    Parameters

    • row1: number

      First row index.

    • row2: number

      Second row index.

    Returns this

  • Returns a new 1D array filled row by row with the matrix values.

    Returns number[]

  • Returns a 2D array containing a copy of the matrix data.

    Returns number[][]

  • Returns the trace of the matrix (sum of the diagonal elements).

    Returns number

  • iterator from left to right, from top to bottom yield value

    Returns Generator<number, void, void>

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Parameters

    • value: ScalarOrMatrix

    Returns this

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Check that the provided value is a Matrix and tries to instantiate one if not.

    Parameters

    • value: any

      The value to check.

    Returns Matrix

  • Creates a column vector, a matrix with only one column.

    Parameters

    • newData: ArrayLike<number>

      A 1D array containing data for the vector.

    Returns Matrix

    The new matrix.

  • Creates a diagonal matrix based on the given array.

    Parameters

    • data: ArrayLike<number>

      Array containing the data for the diagonal.

    • Optionalrows: number

      Number of rows. Default: data.length.

    • Optionalcolumns: number

      Number of columns. Default: rows.

    Returns Matrix

    • The new diagonal matrix.
  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Creates an identity matrix with the given dimension. Values of the diagonal will be 1 and others will be 0.

    Parameters

    • rows: number

      Number of rows.

    • Optionalcolumns: number

      Number of columns. Default: rows.

    • Optionalvalue: number

      Value to fill the diagonal with. Default: 1.

    Returns Matrix

    • The new identity matrix.
  • Constructs a matrix with the chosen dimensions from a 1D array.

    Parameters

    • newRows: number

      Number of rows.

    • newColumns: number

      Number of columns.

    • newData: ArrayLike<number>

      A 1D array containing data for the matrix.

    Returns Matrix

    The new matrix.

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Returns a matrix whose elements are the maximum between matrix1 and matrix2.

    Parameters

    • matrix1: MaybeMatrix
    • matrix2: MaybeMatrix

    Returns Matrix

  • Returns a matrix whose elements are the minimum between matrix1 and matrix2.

    Parameters

    • matrix1: MaybeMatrix
    • matrix2: MaybeMatrix

    Returns Matrix

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Creates a matrix with the given dimensions. Values will be set to one.

    Type Parameters

    Parameters

    • rows: number

      Number of rows.

    • columns: number

      Number of columns.

    Returns M

    The new matrix.

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Creates a matrix with the given dimensions. Values will be randomly set.

    Parameters

    • rows: number

      Number of rows.

    • columns: number

      Number of columns.

    • Optionaloptions: IRandomOptions

      Options object.

    Returns Matrix

    The new matrix.

  • Creates a matrix with the given dimensions. Values will be random integers.

    Parameters

    • rows: number

      Number of rows.

    • columns: number

      Number of columns.

    • Optionaloptions: IRandomIntOptions

    Returns Matrix

    • The new matrix.
  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Creates a row vector, a matrix with only one row.

    Parameters

    • newData: ArrayLike<number>

      A 1D array containing data for the vector.

    Returns Matrix

    The new matrix.

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Parameters

    • matrix: MaybeMatrix
    • value: ScalarOrMatrix

    Returns Matrix

  • Creates a matrix with the given dimensions. Values will be set to zero. This is equivalent to calling the Matrix constructor.

    Type Parameters

    Parameters

    • rows: number

      Number of rows.

    • columns: number

      Number of columns.

    Returns _M

    The new matrix.