How to compute the trace of a tensor? Let $T$ a $(p,q)$-tensor. How can I compute its trace?
Some references states that it is the trace of $T(w_1,\ldots,w_{p-1},\cdot,V_1,\ldots,V_{q-1},\cdot)$ buw how can I compute this in practice?
 A: Let $T$ be a $(p, q)$ tensor on a real vector space $V$. If $\{e_k\}$ is a basis for $V$, and $\{e^k\}$ denotes the dual basis, then $\{e_{i_1}\otimes\dots\otimes e_{i_p}\otimes e^{j_1}\otimes\dots\otimes e^{j_q}\}$ is a basis for the vector space of $(p, q)$ tensors where 
$$e_{i_1}\otimes\dots\otimes e_{i_p}\otimes e^{j_1}\otimes\dots\otimes e^{j_q}(w^1, \dots, w^p, V_1, \dots, V_q) = w^1(e_{i_1})\dots w^p(e_{i_p})e^{j_1}(V_1)\dots e^{j_q}(V_q)$$ 
so $T = T^{i_1\dots i_p}_{j_1\dots j_q}e_{i_1}\otimes\dots\otimes e_{i_p}\otimes e^{j_1}\otimes\dots\otimes e^{j_q}$ for some real numbers $T^{i_1\dots i_p}_{j_1\dots j_q}$. In fact, $T^{i_1\dots i_p}_{j_1\dots j_q} = T(e^{i_1}, \dots, e^{i_p}, e_{j_1}, \dots, e_{j_q})$.
If we trace the last upper and lower index, we obtain a $(p - 1, q - 1)$-tensor $\operatorname{tr} T$ defined by 
$$\operatorname{tr} T(w^1, \dots, w^{p-1}, V_1, \dots, V_{q-1}) = \operatorname{tr}(T(w^1, \dots, w^{p-1},\, \cdot\, , V_1, \dots, V_{q-1},\, \cdot\, )).$$
Using the above expression for $T$, we have
\begin{align*}
& \operatorname{tr} T(w^1, \dots, w^{p-1}, V_1, \dots, V_{q-1})\\
&= \operatorname{tr}(T(w^1, \dots, w^{p-1},\, \cdot\, , V_1, \dots, V_{q-1},\, \cdot\, ))\\
&= \operatorname{tr}\left(T^{i_1\dots i_p}_{j_1\dots j_q}w^1(e_{i_1})\dots w^{p-1}(e_{i_{p-1}})e^{j_1}(V_1)\dots e^{j_{q-1}}(V_{q-1})e_{i_p}\otimes e^{j_q}\right)\\
&= T^{i_1\dots i_p}_{j_1\dots j_q}w^1(e_{i_1})\dots w^{p-1}(e_{i_{p-1}})e^{j_1}(V_1)\dots e^{j_{q-1}}(V_{q-1})\operatorname{tr}(e_{i_p}\otimes e^{j_q})\\
&= T^{i_1\dots i_p}_{j_1\dots j_q}w^1(e_{i_1})\dots w^{p-1}(e_{i_{p-1}})e^{j_1}(V_1)\dots e^{j_{q-1}}(V_{q-1})\delta_{i_p}^{j_q}\\
&= T^{i_1\dots i_p}_{j_1\dots j_q}\delta_{i_p}^{j_q}e_{i_1}\otimes\dots\otimes e_{i_{p-1}}\otimes e^{j_1}\otimes\dots\otimes e^{j_{q-1}}(w^1, \dots, w^{p-1}, V_1, \dots, V_{q-1}).
\end{align*}
So $\operatorname{tr} T = (\operatorname{tr}T)^{i_1\dots i_{p-1}}_{j_1\dots j_{q-1}}e_{i_1}\otimes\dots\otimes e_{i_{p-1}}\otimes e^{j_1}\otimes\dots\otimes e^{j_{q-1}}$ where 
$$(\operatorname{tr}T)^{i_1\dots i_{p-1}}_{j_1\dots j_{q-1}} = T^{i_1\dots i_p}_{j_1\dots j_q}\delta_{i_p}^{j_q} = \sum_k T^{i_1\dots i_{p-1}k}_{j_1\dots j_{q-1}k}.$$ 
So if you know the expression of $T$ in a basis, you can determine an expression for $\operatorname{tr} T$ in the same basis.
