tensor v0.7.0 Matrix

Summary

Functions

Returns the n-th column of the matrix as a Vector

Returns the columns of this matrix as a list of Vectors

Creates a square matrix where the diagonal elements are filled with the elements of list. The second argument is an optional identity to be used for all elements not part of the diagonal

Builds a Matrix up from a list of vectors

Returns the values in the main diagonal (top left to bottom right) as list

Calculates the Scalar Multiplication or Matrix Multiplication of a * b

Creates a new matrix of dimensions width x height

Returns the n-th row of the matrix as a Vector

Takes a vector, and returns a 1×n matrix

Returns the rows of this matrix as a list of Vectors

True if the matrix is square and the same as its transpose

Converts a matrix to a list of lists

Returns the sum of the main diagonal of a square matrix

Functions

add(matrix, num)
column(matrix, n)

Returns the n-th column of the matrix as a Vector.

If you’re doing a lot of calls to column, consider transposing the matrix and calling rows on that transposed matrix, as it will be faster.

column_matrix(tensor)
columns(tensor)

Returns the columns of this matrix as a list of Vectors.

diag(list, identity \\ 0)

Creates a square matrix where the diagonal elements are filled with the elements of list. The second argument is an optional identity to be used for all elements not part of the diagonal.

flip_horizontal(matrix)
flip_vertical(tensor)
from_rows(list_of_vectors)

Builds a Matrix up from a list of vectors.

Will only work as long as the vectors have the same length.

identity(diag_identity \\ 1, size, rest_identity \\ 0)

Creates an ‘identity’ matrix.

This is a square matrix of size size that has the diag_identity value (default: 1) at the diagonal, and the rest is 0. Optionally pass in a third argument, which is the value the rest of the elements in the matrix will be set to.

main_diagonal(tensor)

Returns the values in the main diagonal (top left to bottom right) as list

mult(matrix, num)

Calculates the Scalar Multiplication or Matrix Multiplication of a * b.

If b is a number, then a new matrix where all values will be multiplied by b are returned.

if b is a matrix, then Matrix Multiplication is performed.

This will only work as long as the height of a is the same as the width of b.

This operation internally builds up a list-of-lists, and finally transforms that back to a matrix.

new(list_of_lists \\ [], width, height, identity \\ 0)

Creates a new matrix of dimensions width x height.

Optionally pass in a fourth argument, which will be the default values the matrix will be filled with. (default: 0)

rotate_180(matrix)
rotate_clockwise(matrix)
rotate_counterclockwise(matrix)
row(matrix, n)

Returns the n-th row of the matrix as a Vector.

This is the same as doing matrix[n]

row_matrix(tensor)

Takes a vector, and returns a 1×n matrix.

rows(tensor)

Returns the rows of this matrix as a list of Vectors.

square?(tensor)
symmetric?(tensor)

True if the matrix is square and the same as its transpose.

to_list(matrix)

Converts a matrix to a list of lists.

trace(tensor)

Returns the sum of the main diagonal of a square matrix.

Note that this method will fail when called with a non-square matrix

transpose(tensor)