tensor v0.7.2 Matrix

Summary

Functions

Elementwise addition of matrixs matrix_a and matrix_b

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 the given List or Vector. The second argument is an optional identity to be used for all elements not part of the diagonal

Elementwise division of matrix_a and matrix_b. Make sure that the identity of matrix_b isn’t 0 before doing this

Returns the element at index from matrix

Builds a Matrix up from a list of vectors

Returns the element at index from matrix. If index is out of bounds, returns default

Returns the current identity of matrix matrix

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

true if a is a Matrix

Elementwise multiplication of matrix_a with matrix_b

Creates a new matrix of dimensions width x height

Calculates the product of matrix with matrix, exponent times. If exponent == 0, then the result will be the identity matrix with the same dimensions as the given matrix

Calculates the Matrix Product. This is a new matrix, obtained by multiplying taking the m rows of the m_by_n_matrix, the p columns of the n_by_p_matrix and calculating the dot-product (See Vector.dot_product/2 of these two n-length vectors. The resulting values are stored at position [m][p] in the final matrix

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

Elementwise subtraction of matrix_b from matrix_a

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

Returns the sum of the main diagonal of a square matrix

Functions

add(a, b)

See Tensor.add/2.

add_matrix(matrix_a, matrix_b)

Elementwise addition of matrixs matrix_a and matrix_b.

add_number(a, b)

See Tensor.add_number/2.

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.

dense_map_with_coordinates(matrix, function)

See Tensor.dense_map_with_coordinates/2.

diag(list_or_vector, identity \\ 0)

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

div(a, b)

See Tensor.div/2.

div_matrix(matrix_a, matrix_b)

Elementwise division of matrix_a and matrix_b. Make sure that the identity of matrix_b isn’t 0 before doing this.

div_number(a, b)

See Tensor.div_number/2.

fetch(matrix, index)

Returns the element at index from matrix.

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.

get(matrix, index, default)

Returns the element at index from matrix. If index is out of bounds, returns default.

get_and_update(matrix, index, function)

See Tensor.get_and_update/3.

identity(matrix)

Returns the current identity of matrix matrix.

identity_matrix(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.

lift(matrix)

See Tensor.lift/1.

main_diagonal(tensor)

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

map(matrix, function)

See Tensor.map/2.

matrix?(a)

true if a is a Matrix.

merge(matrix_a, matrix_b, function)

See Tensor.merge/3.

merge_with_index(matrix_a, matrix_b, function)

See Tensor.merge_with_index/3.

mul(a, b)

See Tensor.mul/2.

mul_matrix(matrix_a, matrix_b)

Elementwise multiplication of matrix_a with matrix_b.

mul_number(a, b)

See Tensor.mul_number/2.

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)

pop(matrix, index, default)

See Tensor.pop/3.

power(tensor)
power(matrix, exponent)

Calculates the product of matrix with matrix, exponent times. If exponent == 0, then the result will be the identity matrix with the same dimensions as the given matrix.

This is calculated using the fast exponentiation by squaring algorithm.

product(m_by_n_matrix, n_by_p_matrix)

Calculates the Matrix Product. This is a new matrix, obtained by multiplying taking the m rows of the m_by_n_matrix, the p columns of the n_by_p_matrix and calculating the dot-product (See Vector.dot_product/2 of these two n-length vectors. The resulting values are stored at position [m][p] in the final matrix.

There is no way to perform this operation in a sparse way, so it is performed dense. The identities of the two matrices cannot be kept; nil is used as identity of the output Matrix.

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.

sparse_map_with_coordinates(matrix, function)

See Tensor.sparse_map_with_coordinates/2.

square?(tensor)
sub(a, b)

See Tensor.sub/2.

sub_matrix(matrix_a, matrix_b)

Elementwise subtraction of matrix_b from matrix_a.

sub_number(a, b)

See Tensor.sub_number/2.

symmetric?(tensor)

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

to_list(matrix)

See Tensor.to_list/1.

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)
with_coordinates(matrix)

See Tensor.with_coordinates/1.