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
.
Creates an 'identity' 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
add(a, b)
See Tensor.Tensor.add/2
.
add_matrix(matrix_a, matrix_b)
Elementwise addition of matrixs matrix_a
and matrix_b
.
add_number(a, b)
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(vector)
columns(matrix)
Returns the columns of this matrix as a list of Vectors.
dense_map_with_coordinates(matrix, 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.
div(a, b)
See Tensor.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)
fetch(matrix, index)
Returns the element at index
from matrix
.
flip_horizontal(matrix)
flip_vertical(matrix)
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.
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.
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)
height(tensor)
Returns the height
of the matrix.
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.Tensor.lift/1
.
main_diagonal(matrix)
Returns the values in the main diagonal (top left to bottom right) as list
map(matrix, function)
See Tensor.Tensor.map/2
.
matrix?(a)
true
if a
is a Matrix.
merge(matrix_a, matrix_b, function)
merge_with_index(matrix_a, matrix_b, function)
mult(a, b)
See Tensor.Tensor.mult/2
.
mult_matrix(matrix_a, matrix_b)
Elementwise multiplication of matrix_a
with matrix_b
.
mult_number(a, b)
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
)
pop(matrix, index, default)
See Tensor.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(vector)
Takes a vector, and returns a 1×n
matrix.
rows(matrix)
Returns the rows of this matrix as a list of Vectors.
sparse_map_with_coordinates(matrix, function)
square?(tensor)
sub(a, b)
See Tensor.Tensor.sub/2
.
sub_matrix(matrix_a, matrix_b)
Elementwise subtraction of matrix_b
from matrix_a
.
sub_number(a, b)
symmetric?(matrix)
True if the matrix is square and the same as its transpose.
to_list(matrix)
to_sparse_map(matrix)
trace(matrix)
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(matrix)
width(tensor)
Returns the width
of the matrix.