## Libraries.Compute.Matrix Documentation

This class is a two dimensional matrix of number variables.

Example Code

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 1.1)
output matrix:ToText()
end
end
``````

Inherits from: Libraries.Language.Object

## Actions Documentation

This method is used to add a value to all the elements in a Matrix. Attribute Parameter value The value to be added to the matrix elements. Attribute Returns A new matrix after the operation is performed.

• number value

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
output matrix:ToText()
end
end
``````

This method is used to add all the elements in a Matrix by the values in another Matrix. The dimensions of the matrices must be the same. Attribute Parameter matrix The matrix to add to the current matrix. Attribute Returns A new matrix after the operation is performed.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2
matrix2:Fill(2, 3, 2.0)
output matrix:ToText()
end
end
``````

### Calculate(Libraries.Compute.MatrixTransform.MatrixCalculation calculate)

This is a blueprint method for creating a Matrix Calculation class.

#### Return

number: A new matrix after the operation is performed.

Example

``````use Libraries.Compute.MatrixTransform.MatrixTransform
use Libraries.Compute.Matrix

action Calculate(Matrix matrix) returns Matrix
Matrix newMatrix
newMatrix:SetSize(matrix)
row = 0
repeat matrix:GetRows() times
col = 0
repeat matrix:GetColumns() times
newMatrix:Set(row, col, matrix:Get(row, col) + 3)                    col = col + 1
end
row = row + 1
end
return newMatrix
end
end
``````

### CenterByColumn()

This action centers the matrix by column and returns a new matrix. Subtracts the column mean from each value in the column. Attribute Returns a Matrix.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 7)
Matrix newMatrix = matrix:CenterByColumn()
end
end
``````

### CenterByRow()

This action centers the matrix by row and returns a new matrix. Subtracts the row mean from each value in the row. Attribute Returns a Matrix.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 7)
Matrix newMatrix = matrix:CenterByRow()
end
end
``````

### Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

#### Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

``````Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
``````

This method converts the Matrix to a dataframe with columns labelled by a given text array. The size of the column header array must be equal to the number of matrix columns. Attribute Returns A dataframe with the column headers.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main

Matrix matrix
matrix:Fill(2, 3, 10.0)
output frame:ToText()
end
end
``````

### Copy()

This method returns a copy of a Matrix. Attribute Returns A new copied matrix.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2 = matrix:Copy()
output matrix2:ToText()
end
end
``````

### Divide(number value)

This method is used to divide all the elements in a Matrix by a value. Attribute Parameter value The value to divide the matrix elements by. Attribute Returns A new matrix after the operation is performed.

• number value

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
matrix = matrix:Divide(2.0)
output matrix:ToText()
end
end
``````

### DivideElements(Libraries.Compute.Matrix matrix)

This method is used to divide all the elements in a Matrix by the values in another Matrix. The dimensions of the matrices must be the same. Attribute Parameter matrix The matrix of values to divide by the current matrix values. Attribute Returns A new matrix after the operation is performed.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2
matrix2:Fill(2, 3, 2.0)
matrix = matrix:DivideElements(matrix2)
output matrix:ToText()
end
end
``````

### DoubleCenter()

This action double centers the matrix and returns a new matrix. This is useful in cases like estimating a population covariance matrix using a sample covariance matrix. Attribute Returns a Matrix.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 7)
Matrix newMatrix = matrix:DoubleCenter()
end
end
``````

### Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

#### Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

``````use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
``````

### Fill(number fillValue)

This method fills the matrix with the specified value. Attribute Parameter fillValue The value to place in each element in the matrix. Attribute Returns A new matrix after the operation is performed.

#### Parameters

• number fillValue

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0)
matrix = matrix:Fill(1.1)
output matrix:ToText()
end
end
``````

### Fill(integer rows, integer columns, number value)

This method fills a matrix with a specified number of rows and columns with the same value. Attribute Parameter rows The number of rows for the matrix. Attribute Parameter columns The number of columns for the matrix. Attribute Parameter value The value to place in each element in the matrix. Attribute Returns A new matrix after the operation is performed.

#### Parameters

• integer rows
• integer columns
• number value

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2 = matrix:Copy()
output matrix2:ToText()
end
end
``````

### FillByColumn(integer columns, Libraries.Compute.Matrix matrix)

This method fills a matrix from the values of a single column matrix for a specified number of columns. Attribute Parameter columns The number of columns to fill. Attribute Parameter matrix The set of values for each column.

#### Parameters

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
Matrix matrix2
matrix2:Fill(1, 3, 1.1)
matrix:FillByColumn(3, matrix2)
output matrix:ToText()
end
end
``````

### FillByColumn(integer columns, Libraries.Containers.Array<number> array)

This method fills a matrix from the values in an array of numbers for a specified number of columns. Attribute Parameter columns The number of columns to fill. Attribute Parameter array The set of values for each column.

#### Parameters

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
Array<number> array
matrix:FillByColumn(3, array)
output matrix:ToText()
end
end
``````

### FillByRow(integer rows, Libraries.Containers.Array<number> array)

This method fills a matrix from the values in an array of numbers for a specified number of rows. Attribute Parameter rows The number of rows to fill. Attribute Parameter array The set of values for each row.

#### Parameters

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
Array<number> array
matrix:FillByRow(3, array)
output matrix:ToText()
end
end
``````

### FillByRow(integer rows, Libraries.Compute.Matrix matrix)

This method fills a matrix from the values of a single row matrix for a specified number of rows. Attribute Parameter rows The number of rows to fill. Attribute Parameter matrix The set of values for each row.

#### Parameters

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
Matrix matrix2
matrix2:Fill(1, 3, 1.1)
matrix:FillByRow(3, matrix2)
output matrix:ToText()
end
end
``````

### FlipHorizontal()

This method flips the array vertically, from top to bottom Attribute Returns A new matrix after the operation is performed.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
matrix = matrix:FlipHorizontal()
output matrix:ToText()
end
end
``````

### FlipVertical()

This method flips the array vertically, from top to bottom Attribute Returns A new matrix after the operation is performed.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetRow(0, 1.1)
matrix:SetRow(1, 2.1)
matrix:SetRow(2, 3.1)
matrix = matrix:FlipVertical()
output matrix:ToText()
end
end
``````

### Get(integer row, integer column)

This method is used to get the value in a specified location in the matrix.

#### Parameters

• integer row: The row number of the item.
• integer column: The column number of the item.

#### Return

number: The value of the item in the matrix.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 1.1)
output matrix:Get(1, 1)
end
end
``````

### GetColumn(integer column)

This method is used to get a column of a Matrix returned as a new matrix.

#### Parameters

• integer column: The column number of the matrix to return.

#### Return

Libraries.Compute.Matrix: A matrix containing only the specified column.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Matrix col1 = matrix:GetColumn(0)
output col1:ToText()
end
end
``````

### GetColumnArray(integer column)

This method is used to get a column of a Matrix returned as an array of numbers.

#### Parameters

• integer column: The column number of the matrix to return.

#### Return

Libraries.Containers.Array: An array containing only the specified row.

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Array<number> col1 = matrix:GetColumnArray(0)
output col1:GetSize()
end
end
``````

### GetColumnMajorArray()

This method is used to get a list of all the elements in a Matrix ordered by column returned as an array of numbers.

#### Return

Libraries.Containers.Array: An array containing all the elements in matrix in order by column.

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Array<number> col1 = matrix:GetColumnMajorArray()
output col1:GetSize()
end
end
``````

### GetColumnVector(integer column)

This method is used to get a column of a Matrix returned as an vector of numbers.

#### Parameters

• integer column: The column number of the matrix to return.

#### Return

Libraries.Compute.Vector: An vector containing only the specified column.

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Vector col1 = matrix:GetColumnVector(0)
output col1:GetSize()
end
end
``````

### GetColumns()

This method is used to get the number of columns in a matrix.

#### Return

integer: The number of columns in the matrix.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:SetSize(2, 3)
output matrix:GetColumns()
end
end
``````

### GetDeterminant()

This method returns the determinant of a square matrix. The determinant is the product of the eigenvalues. Attribute Returns determinant of the matrix

#### Return

number:

Example

``````
use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
output matrix:GetDeterminant()
end
end
``````

### GetDiagonal()

This method returns the diagonal of a square matrix Attribute Returns Matrix of the diagonal values.

#### Return

Example

``````
use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
output matrix:GetDiagonal():ToText()
end
end
``````

### GetHashCode()

This action gets the hash code for an object.

#### Return

integer: The integer hash code of the object.

Example

``````Object o
integer hash = o:GetHashCode()
``````

### GetMaximum()

This method returns the value of the maximum element in a Matrix Attribute Returns The value of the largest element in the matrix.

#### Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetMaximum()
end
end
``````

### GetMean()

This method returns the mean (average) of all the elements in a Matrix Attribute Returns The mean of all the elements in the matrix.

#### Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetMean()
end
end
``````

### GetMedian()

This method returns the median (middle value) of all the elements in a Matrix Attribute Returns The median of all the elements in the matrix.

#### Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetMedian()
end
end
``````

### GetMinimum()

This method returns the value of the minimum element in a Matrix Attribute Returns The value of the smallest element in the matrix.

#### Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetMinimum()
end
end
``````

### GetModes()

This method returns an array of all the modes (most common value) of a Matrix Attribute Returns An array of the modes of all the elements in the matrix.

#### Return

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
Array<number> modes = matrix:GetModes()
output modes:Get(0)
end
end
``````

### GetModesAsText()

This method returns an comma separated value of all the modes (most common value) of a Matrix Attribute Returns An comma separated list of the modes of all the elements in the matrix.

#### Return

text:

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetModesAsText()
end
end
``````

### GetPercentile(number rank)

This method returns the value at a given percentile rank of a Matrix, assuming the elements in the Matrix are all sorted.

• number rank

#### Return

number: The value at a given percentile rank of a Matrix.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetPercentile(0.40)
end
end
``````

### GetPopulationStandardDeviation()

This method returns the population standard deviation of all the elements in a Matrix Attribute Returns The standard deviation of all the elements in the matrix.

#### Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetStandardDeviation()
end
end
``````

### GetPopulationVariance()

This method returns the population variance of all the elements in a Matrix Attribute Returns The variance of all the elements in the matrix.

#### Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetVariance()
end
end
``````

### GetRow(integer row)

This method is used to get a row of a Matrix returned as a new matrix.

#### Parameters

• integer row: The row number of the matrix to return.

#### Return

Libraries.Compute.Matrix: A matrix containing only the specified row.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Matrix row1 = matrix:GetRow(0)
output row1:ToText()
end
end
``````

### GetRowArray(integer row)

This method is used to get a row of a Matrix returned as an array of numbers.

#### Parameters

• integer row: The row number of the matrix to return.

#### Return

Libraries.Containers.Array: An array containing only the specified row.

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Array<number> row1 = matrix:GetRowArray(0)
output row1:GetSize()
end
end
``````

### GetRowMajorArray()

This method is used to get a list of all the elements in a Matrix ordered by row returned as an array of numbers.

#### Return

Libraries.Containers.Array: An array containing all the elements in the matrix ordered by row .

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Array<number> row1 = matrix:GetRowMajorArray()
output row1:GetSize()
end
end
``````

### GetRowVector(integer row)

This method is used to get a row of a Matrix returned as an vector of numbers.

#### Parameters

• integer row: the row number of the matrix to return.

#### Return

Libraries.Compute.Vector: An vector containing only the specified row.

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 1.1)
Vector row1 = matrix:GetRowVector(0)
output row1:GetSize()
end
end
``````

### GetRows()

This method is used to get the number of columns in a matrix.

#### Return

integer: The number of rows in the matrix.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:SetSize(2, 3)
output matrix:GetRows()
end
end
``````

### GetSize()

This method is used to get the number of elements in a matrix.

#### Return

integer: The total number of elements in the matrix.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:SetSize(2, 3)
output matrix:GetSize()
end
end
``````

### GetStandardDeviation()

This method returns the sample standard deviation of all the elements in a Matrix Attribute Returns The standard deviation of all the elements in the matrix.

#### Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetStandardDeviation()
end
end
``````

### GetSubMatrix(integer offsetRow, integer offsetColumn, integer rows, integer columns)

This method extracts a sub matrix from within a matrix, starting at the offsetRow and offsetColumn (relative to 0,0 in the upper right corner). The sub matrix will have the number of rows and columns specified by those parameters Attribute Parameter offsetRow The row offset for the first element in the new matrix. Attribute Parameter offsetColumn The column offset for the first element in the new matrix. Attribute Parameter rows The number of rows to extract. Attribute Parameter columns The number of columns to extract. Attribute Returns A new matrix after the operation is performed.

#### Parameters

• integer offsetRow
• integer offsetColumn
• integer rows
• integer columns

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
matrix:SetColumn(3, 4.1)
matrix = matrix:GetSubMatrix(1, 1, 2, 2)
output matrix:ToText()
end
end
``````

### GetSumOfSquares()

This method returns the sum of all the elements squared in a Matrix Attribute Returns The sum of all the elements squared in the matrix.

#### Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetSumOfSquares()
end
end
``````

### GetTotal()

This method returns the sum of all the elements in a Matrix Attribute Returns The sum of all the elements in the matrix.

#### Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetTotal()
end
end
``````

### GetTrace()

This method returns the trace of a square matrix. The trace is the sum of the main diagonal. Attribute Returns trace of the matrix

#### Return

number:

Example

``````
use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
output matrix:GetTrace()
end
end
``````

### GetUpperTriangularSubMatrix()

This method returns a matrix conisting of only the upper triangular portion of this matrix. It does not include the diagonal values. It will have zeros in all diagonal and lower indices.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 1.0)
matrix = matrix:GetUpperTriangularSubMatrix()
output matrix:ToText()
end
end
``````

### GetVariance()

This method returns the sample variance of all the elements in a Matrix Attribute Returns The variance of all the elements in the matrix.

#### Return

number:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
output matrix:GetVariance()
end
end
``````

### Identity()

This method returns the identity matrix for a square matrix. An identity matrix with ones along the main diagonal from top left to bottom right and zeroes everywhere else. Attribute Returns A new identity matrix.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
matrix = matrix:Identity()
output matrix:ToText()
end
end
``````

### Inverse()

This method returns the inverse matrix of a square matrix. Attribute Returns A new inverse matrix.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
matrix = matrix:Inverse()
output matrix:ToText()
end
end
``````

### IsDiagonal()

This method returns true if the matrix has zeros is all positions except at the diagonal. Attribute Returns a boolean.

#### Return

boolean:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
output matrix:IsDiagonal()
end
end
``````

### IsSquare()

This method returns true if the matrix rows and columns are equal in size therefore it is square. Attribute Returns a boolean.

#### Return

boolean:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
output matrix:IsSquare()
end
end
``````

### IsSymmetric()

This method returns true if the tranpose of this matrix is equal to itself therefore it is symmetric. Attribute Returns a boolean.

#### Return

boolean:

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
output matrix:IsSymmetric()
end
end
``````

### Multiply(number value)

This method is used to multiply all the elements in a Matrix by a value. Attribute Parameter value The value to multiply the matrix elements by. Attribute Returns A new matrix after the operation is performed.

• number value

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
matrix = matrix:Multiply(2.0)
output matrix:ToText()
end
end
``````

### Multiply(Libraries.Compute.Vector vector)

This method multiplies the matrix by a vector. The dimensions of the vector must match the rows of the matrix.

#### Return

Example

``````Attribute Parameter vector The vector to multiply by the current matrix.

Attribute Returns A new Vector after the operation is performed.

use Libraries.Compute.Matrix
use Libraries.Compute.Vector

class Main
action Main
Matrix matrix
matrix:SetSize(2,3)
matrix:Set(0, 0, 1)
matrix:Set(0, 1, -1)
matrix:Set(0, 2, 2)

matrix:Set(1, 0, 0)
matrix:Set(1, 1, -3)
matrix:Set(1, 2, 1)

Vector vector
vector:SetSize(3)
i = 2
repeat while i >= 0
vector:Set(2 - i, i)
i = i - 1
end
Vector result = matrix:Multiply(vector)
output result:ToText()
end
end
``````

### Multiply(Libraries.Compute.Matrix matrix)

This method performs a multiplication operation on two matrices. The dimensions of the matrices must be compatible so that the columns in the first matrix are equal to the rows in the second matrix.

#### Return

Example

``````Attribute Parameter matrix The matrix to multiply by the current matrix.

Attribute Returns A new matrix after the operation is performed.

use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2
matrix2:Fill(3, 2, 2.0)
matrix = matrix:Multiply(matrix2)
output matrix:ToText()
end
end
``````

### MultiplyElements(Libraries.Compute.Matrix matrix)

This method is used to multiply all the elements in a Matrix by the values in another Matrix. The dimensions of the matrices must be the same. Attribute Parameter matrix The matrix of values to multiply by the current matrix values. Attribute Returns A new matrix after the operation is performed.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2
matrix2:Fill(2, 3, 2.0)
matrix = matrix:MultiplyElements(matrix2)
output matrix:ToText()
end
end
``````

### Reshape(integer offsetRow, integer offsetColumn, integer rows, integer columns, number fillValue)

This method shifts a matrix a given number of offsetRows and offsetColumns (relative to 0,0 in the upper right corner). The new matrix will have the number of rows and columns specified by those parameters and any empty values in the new matrix will be filled with fillValue. Attribute Parameter offsetRow The row offset for the first element in the new matrix. Attribute Parameter offsetColumn The column offset for the first element in the new matrix. Attribute Parameter rows The number of rows to extract. Attribute Parameter columns The number of columns to extract. Attribute Parameter fillValue The value to fill in any undefined cells in the new matrix.. Attribute Returns A new matrix after the operation is performed.

#### Parameters

• integer offsetRow
• integer offsetColumn
• integer rows
• integer columns
• number fillValue

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
matrix:SetColumn(3, 4.1)
matrix = matrix:Reshape(1, 1, 6, 6, 0.0)
output matrix:ToText()
end
end
``````

### RotateLeft()

This method rotates a Matrix to the left Attribute Returns A new matrix after the operation is performed.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
matrix = matrix:RotateLeft()
output matrix:ToText()
end
end
``````

### RotateRight()

This method rotates a Matrix to the right Attribute Returns A new matrix after the operation is performed.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
matrix = matrix:RotateRight()
output matrix:ToText()
end
end
``````

### Round(integer decimalPlace)

This method rounds the values this matrix to the given decimalPlace and returns a new matrix. Attribute Returns a Matrix.

#### Parameters

• integer decimalPlace

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 7.8887)
Matrix newMatrix = matrix:Round(2)
end
end
``````

### Set(integer row, integer column, number value)

This method is used to set the value in a specified location in the matrix.

#### Parameters

• integer row: The row number of the item.
• integer column: The column number of the item.
• number value: The value to set. use Libraries.Compute.Matrix class Main action Main Matrix matrix matrix:Fill(3, 3, 1.1) matrix:Set(1, 1, 2.2) output matrix:Get(1, 1) end end

### SetColumn(integer column, Libraries.Containers.Array<number> array)

This method is used to set the elements in a column of a Matrix with a list of numbers in an array. The length of the array must match the height of the Matrix. Attribute parameter column The column number of the array to set. Attribute parameter array The array of values to set.

#### Parameters

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 0.0)
Array<number> array
matrix:SetColumn(0, array)
output matrix:ToText()
end
end
``````

### SetColumn(integer column, Libraries.Compute.Matrix matrix)

This method is used to set the elements in a column of a Matrix with a single column matrix. The heights of the matrices must match. Attribute parameter column The column number of the array to set. Attribute parameter matrix The matrix of values to set.

#### Parameters

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 0.0)
Matrix matrix2
matrix2:Fill(2, 1, 1.0)
matrix:SetColumn(0, matrix2)
output matrix:ToText()
end
end
``````

### SetColumn(integer column, number value)

This method is used to set all the elements in a column of a Matrix to a single value. Attribute parameter column The column number of the array to set. Attribute parameter value The value to set in each element of a column.

#### Parameters

• integer column
• number value

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 0.0)
matrix:SetColumn(0, 1.0)
output matrix:ToText()
end
end
``````

### SetLowerThreshold(number cutoffValue, number fillValue)

This method compares each element in a matrix to a lower threshold value and if the element is lower, it sets that element to a fill value. Attribute Parameter cutoffValue The lower threshold value. Attribute Parameter fillValue The value to fill if the element is below the threshold. Attribute Returns A new matrix after the operation is performed.

#### Parameters

• number cutoffValue
• number fillValue

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(1, 3, 1.1)
matrix = matrix:SetLowerThreshold(2.0, 3.0)
output matrix:ToText()
end
end
``````

### SetRow(integer row, Libraries.Containers.Array<number> array)

This method is used to set the elements in a row of a Matrix with a list of numbers in an array. The length of the array must match the width of the Matrix. Attribute parameter row The row number of the array to set. Attribute parameter array The array of values to set.

#### Parameters

Example

``````use Libraries.Compute.Matrix
use Libraries.Containers.Array

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 0.0)
Array<number> array
matrix:SetRow(0, array)
output matrix:ToText()
end
end
``````

### SetRow(integer row, number value)

This method is used to set all the elements in a row of a Matrix to a single value. Attribute parameter row The row number of the array to set. Attribute parameter value The value to set in each element of a row.

#### Parameters

• integer row
• number value

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 0.0)
matrix:SetRow(0, 1.0)
output matrix:ToText()
end
end
``````

### SetRow(integer row, Libraries.Compute.Matrix matrix)

This method is used to set the elements in a row of a Matrix with a single row matrix. The widths of the matrices must match. Attribute parameter row The row number of the array to set. Attribute parameter matrix The matrix of values to set.

#### Parameters

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 0.0)
Matrix matrix2
matrix2:Fill(1, 3, 1.0)
matrix:SetRow(0, matrix2)
output matrix:ToText()
end
end
``````

### SetSize(integer rows, integer columns)

This method is used to set the dimensions of a matrix.

#### Parameters

• integer rows: The number of rows in the matrix.
• integer columns: The number of columns in the matrix.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:SetSize(2, 3)
output matrix:GetSize()
end
end
``````

### SetSize(Libraries.Compute.Matrix matrix)

This method is used to set the dimensions of a matrix to match a different matrix..

#### Parameters

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix1
matrix:SetSize(2, 3)
output matrix:GetSize()
end
end
``````

### SetUpperThreshold(number cutoffValue, number fillValue)

This method compares each element in a matrix to an upper threshold value and if the element is higher, it sets that element to a fill value. Attribute Parameter cutoffValue The upper threshold value. Attribute Parameter fillValue The value to fill if the element is above the threshold. Attribute Returns A new matrix after the operation is performed.

#### Parameters

• number cutoffValue
• number fillValue

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(1, 3, 1.1)
matrix = matrix:SetUpperThreshold(1.0, 0.5)
output matrix:ToText()
end
end
``````

### Shift(integer offsetRow, integer offsetColumn, number fillValue)

This method shifts a matrix a given number of offsetRows and offsetColumns (relative to 0,0 in the upper left corner). The new matrix is the same size and any empty values in the new matrix will be filled with fillValue. Attribute Parameter offsetRow The row offset for the first element in the new matrix. Attribute Parameter offsetColumn The column offset for the first element in the new matrix. Attribute Parameter fillValue The value to fill in any undefined cells in the new matrix. Attribute Returns A new matrix after the operation is performed.

#### Parameters

• integer offsetRow
• integer offsetColumn
• number fillValue

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
matrix:SetColumn(3, 4.1)
matrix = matrix:Shift(1, 1, 0.0)
output matrix:ToText()
end
end
``````

### SquareRootElements()

This method applies a square root to each element in the Matrix. Attribute Returns A copied matrix with the calculation applied.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2 = matrix:SquareRootElements()
output matrix2:ToText()
end
end
``````

### Subtract(number value)

This method is used to subtract a value from all the elements in a Matrix. Attribute Parameter value The value to be subtracted from the matrix elements. Attribute Returns A new matrix after the operation is performed.

• number value

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
matrix = matrix:Subtract(1.0)
output matrix:ToText()
end
end
``````

### SubtractElements(Libraries.Compute.Matrix matrix)

This method is used to subtract all the elements in a Matrix from the values in another Matrix. The dimensions of the matrices must be the same. Attribute Parameter matrix The matrix to subtract from the current matrix. Attribute Returns A new matrix after the operation is performed.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2
matrix2:Fill(2, 3, 2.0)
matrix = matrix:SubtractElements(matrix2)
output matrix:ToText()
end
end
``````

### TensorProduct(Libraries.Compute.Matrix matrix)

This method performs a multiplication operation on two matrices. It multiplies each element in this matrix (me) by the entire parameter matrix.

#### Return

Example

``````Attribute Parameter matrix The matrix to multiply by the current matrix.

Attribute Returns A new matrix after the operation is performed.

use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(2, 3, 10.0)
Matrix matrix2
matrix2:Fill(3, 2, 2.0)
matrix = matrix:TensorProduct(matrix2)
output matrix:ToText()
end
end
``````

### ToText()

This method prints a matrix in text format for easy viewing.

#### Return

text: A text value representation of the matrix.

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(3, 3, 1.0)
output matrix:ToText()
end
end
``````

### Transform(Libraries.Compute.MatrixTransform.MatrixTransform transform)

This is a blueprint method for creating a Matrix Transform class.

#### Return

Libraries.Compute.Matrix: A new matrix after the operation is performed.

Example

``````use Libraries.Compute.MatrixTransform.MatrixTransform
use Libraries.Compute.Matrix

action Transform(Matrix matrix) returns Matrix
Matrix newMatrix
newMatrix:SetSize(matrix)
row = 0
repeat matrix:GetRows() times
col = 0
repeat matrix:GetColumns() times
newMatrix:Set(row, col, matrix:Get(row, col) + 2)                    col = col + 1
end
row = row + 1
end
return newMatrix
end
end
``````

### Transpose()

This method returns the transpose of a matrix where all the rows of the matrix are turned into columns in a new matrix and vice versa. Attribute Returns A new matrix after the operation is performed.

#### Return

Example

``````use Libraries.Compute.Matrix

class Main
action Main
Matrix matrix
matrix:Fill(4, 4, 0.0)
matrix:SetColumn(0, 1.1)
matrix:SetColumn(1, 2.1)
matrix:SetColumn(2, 3.1)
matrix:SetColumn(3, 4.1)
matrix = matrix:Transpose()
output matrix:ToText()
end
end
``````