def trace(mpa, axes=(0, 1)):
"""Compute the trace of the given MPA.
If you specify axes (see partialtrace() for details), you must
ensure that the result has no physical legs anywhere.
:param mpa: MParray
:param axes: Axes for trace, ``(axis1, axis2)`` or ``(axes1, axes2, ...)``
with ``axesN=(axisN_1, axisN_2)`` or ``axesN=None``.
(default: ``(0, 1)``)
:returns: A single scalar of type ``mpa.dtype``
"""
out = partialtrace(mpa, axes)
out = out.to_array()
assert out.size == 1, 'trace must return a single scalar'
return out[None][0]
评论列表
文章目录