trace

tenpy.linalg.np_conserved.trace(a, leg1=0, leg2=1)[source]

Trace of a, summing over leg1 and leg2.

Requires that the contracted legs are contractible (i.e. have opposite charges). Labels are inherited from a.

Parameters:
  • leg1 (str|int) – The leg label or index for the two legs which should be contracted (i.e. summed over).

  • leg2 (str|int) – The leg label or index for the two legs which should be contracted (i.e. summed over).

Returns:

traced – A scalar if a.rank == 2, else an Array of rank a.rank - 2. Equivalent to sum([a.take_slice([i, i], [leg1, leg2]) for i in range(a.shape[leg1])]).

Return type:

Array | a.dtype