tensorA (version 0.36.1)

trace.tensor: Collapse a tensor

Description

Collapses the tensor over dimensions i and j. This is like a trace for matrices or like an inner product of the dimensions i and j.

Usage

trace.tensor(X,i,j)

Arguments

X

the tensor

i

a numeric or character vector of dimensions of X, used for the inner product.

j

a numeric or character vector of dimensions of X with the same length but other elements than i.

Value

A tensor like X with the i and j dimensions removed.

Details

Let be $$X_{i_1\ldots i_n j_1\ldots j_n k_1 \ldots k_d}$$ the tensor. Then the result is given by $$E_{k_1 \ldots k_d}=sum_{i_1\ldots i_n} X_{i_1\ldots i_n i_1\ldots i_n k_1 \ldots k_d} $$ With the Einstein summing convention we would write: $$ E_{k_1 \ldots k_d}=X_{i_1\ldots i_n j_1\ldots j_n k_1 \ldots k_d}\delta_{i_1j_1}\ldots \delta_{i_nj_n}{ E_{k_1...k_d}=X_{i_1...i_n j_1...j_n k_1 ... k_d}\delta_{i_1j_1} ... \delta_{i_nj_n } }$$

See Also

mul.tensor, to.tensor

Examples

Run this code
# NOT RUN {
A <- to.tensor(1:20,c(i=2,j=2,k=5))
A
trace.tensor(A,"i","j")
# }

Run the code above in your browser using DataLab