tensor v2.0.1 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
See Tensor.Tensor.add/2
.
Elementwise addition of matrixs matrix_a
and matrix_b
.
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.
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.
See Tensor.Tensor.div/2
.
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.
Will only work as long as the vectors have the same length.
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.
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.
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
.
Returns the values in the main diagonal (top left to bottom right) as list
See Tensor.Tensor.map/2
.
true
if a
is a Matrix.
See Tensor.Tensor.mult/2
.
Elementwise multiplication of matrix_a
with matrix_b
.
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
)
See Tensor.Tensor.pop/3
.
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.
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.
Returns the n
-th row of the matrix as a Vector.
This is the same as doing matrix[n]
Takes a vector, and returns a 1×n
matrix.
Returns the rows of this matrix as a list of Vectors.
See Tensor.Tensor.sub/2
.
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.
Note that this method will fail when called with a non-square matrix
Returns the width
of the matrix.