This operation is an example of a trace, or a contraction (of indices), of the tensor product $A \otimes B$. In general, you can form a trace for each choice of pair (covariant index, contravariant index) of indices on a particular vector space $\Bbb V$. If you have an inner product on $\Bbb V$ you can identify the two index types with one another and hence contract on any pair of indices on $\Bbb V$.
In our situation there is essentially only one trace. Borrowing the choice of covariant and contravariant indices specified in the comments realizes our operation as the contraction $$\operatorname{tr}: (\Bbb A^* \otimes \Bbb B^* \otimes \Bbb C) \times (\Bbb C^* \otimes \Bbb D) \to \Bbb A^* \otimes \Bbb B^* \otimes \Bbb D$$ for vector spaces $\Bbb A, \Bbb B, \Bbb C, \Bbb D$, of respective dimensions $q$, $m$, $p$, $n$, characterized by its definition on pairs $$((\alpha \otimes \beta \otimes c), (\gamma \otimes d)) \mapsto \gamma(c) \alpha \otimes \beta \otimes d .$$
I suspect that NumPy essentially treats tensors as elements of tensor products of $\Bbb R^k$ for various $k$, each equipped with the standard inner product, in which case we can view our contraction map as
$$\operatorname{tr}: (\Bbb R^q \otimes \Bbb R^m \otimes \Bbb R^p) \times (\Bbb R^p \otimes \Bbb R^n) \to \Bbb R^q \otimes \Bbb R^m \otimes \Bbb R^n.$$
In situations where there is more than one possible trace of the tensor product, one sometimes sees the notation $\operatorname{tr}_{ab}$ to indicate the contraction of the $a$th and $b$th indices (using a background inner product if necessary), so we might denote our trace as $\operatorname{tr}_{34}$.
np.trace(np.tensordot(A, B, axes=0)), but is not equal toA@Bin calculation. If you're familiar with Python/NumPy, would you give me some comments?(FYI: The Einstein summation
– YuuM Mar 02 '23 at 03:40np.einsum('ijk,kl->ijl', A, B)gives the same result asA@B.)np.trace()is simply contracting a pair of indices other than the ones you have in mind. In general, you can form a trace for each choice of pair (covariant index, contravariant index). If you have an inner product on the underlying vector space you can identify the two index types and hence contract any pair of indices. – Travis Willse Mar 02 '23 at 20:46np.tracefunction acceptsaxes1andaxes2parameters where we can specify the axes. Givennp.trace(np.tensordot(A, B, axes=0), axis1=2, axis2=3), we get the same result asA@B. – YuuM Mar 03 '23 at 03:06