tensor v2.1.2 Tensor.Matrix

Link to this section 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.

Converts a sparse map where each key is a [height, width] coordinate list, and each value is anything to a Matrix with the given height, width and contents.

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

Returns the height of the matrix.

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 height x width.

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.

Returns the width of the matrix.

Link to this section Functions

See Tensor.Tensor.add/2.

Link to this function

add_matrix(matrix_a, matrix_b)

Elementwise addition of matrixs matrix_a and matrix_b.

Link to this function

add_number(a, b)

See Tensor.Tensor.add_number/2.

Link to this function

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.

Link to this function

column_matrix(vector)

Link to this function

columns(matrix)

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

Link to this function

dense_map_with_coordinates(matrix, function)

See Tensor.Tensor.dense_map_with_coordinates/2.

Link to this function

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.

See Tensor.Tensor.div/2.

Link to this function

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.

Link to this function

div_number(a, b)

See Tensor.Tensor.div_number/2.

Link to this function

fetch(matrix, index)

Returns the element at index from matrix.

Link to this function

flip_horizontal(matrix)

Link to this function

flip_vertical(matrix)

Link to this function

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.

Link to this function

from_sparse_map(matrix, height, width, identity \\ 0)

Converts a sparse map where each key is a [height, width] coordinate list, and each value is anything to a Matrix with the given height, width and contents.

See to_sparse_map/1 for the inverse operation.

Link to this function

get(matrix, index, default)

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

Link to this function

get_and_update(matrix, index, function)

See Tensor.Tensor.get_and_update/3.

Returns the height of the matrix.

Link to this function

identity(matrix)

Returns the current identity of matrix matrix.

Link to this function

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.

See Tensor.Tensor.lift/1.

Link to this function

main_diagonal(matrix)

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

Link to this function

map(matrix, function)

See Tensor.Tensor.map/2.

true if a is a Matrix.

Link to this function

merge(matrix_a, matrix_b, function)

See Tensor.Tensor.merge/3.

Link to this function

merge_with_index(matrix_a, matrix_b, function)

See Tensor.Tensor.merge_with_index/3.

See Tensor.Tensor.mult/2.

Link to this function

mult_matrix(matrix_a, matrix_b)

Elementwise multiplication of matrix_a with matrix_b.

Link to this function

mult_number(a, b)

See Tensor.Tensor.mult_number/2.

Link to this function

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

Creates a new matrix of dimensions height x width.

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

Link to this function

pop(matrix, index, default)

See Tensor.Tensor.pop/3.

Link to this function

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.

Link to this function

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.

Link to this function

rotate_180(matrix)

Link to this function

rotate_clockwise(matrix)

Link to this function

rotate_counterclockwise(matrix)

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

This is the same as doing matrix[n]

Link to this function

row_matrix(vector)

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

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

Link to this function

sparse_map_with_coordinates(matrix, function)

See Tensor.Tensor.sparse_map_with_coordinates/2.

Link to this function

square?(tensor)

See Tensor.Tensor.sub/2.

Link to this function

sub_matrix(matrix_a, matrix_b)

Elementwise subtraction of matrix_b from matrix_a.

Link to this function

sub_number(a, b)

See Tensor.Tensor.sub_number/2.

Link to this function

symmetric?(matrix)

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

Link to this function

to_list(matrix)

See Tensor.Tensor.to_list/1.

Link to this function

to_sparse_map(matrix)

See Tensor.Tensor.to_sparse_map/1.

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

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

Link to this function

transpose(matrix)

Returns the width of the matrix.

Link to this function

with_coordinates(matrix)

See Tensor.Tensor.with_coordinates/1.