tenpy.linalg.np_conserved.detect_legcharge(flat_array, chargeinfo, legcharges, qtotal=None, qconj=1, cutoff=None)[source]

Calculate a missing LegCharge by looking for nonzero entries of a flat array.

  • flat_array (ndarray) – A flat array, in which we look for non-zero entries.

  • chargeinfo (ChargeInfo) – The nature of the charge.

  • legcharges (list of LegCharge) – One LegCharge for each dimension of flat_array, except for one entry which is None. This missing entry is to be calculated.

  • qconj ({+1, -1}) – qconj for the new calculated LegCharge.

  • qtotal (charges) – Desired total charge of the array. Defaults to zeros.

  • cutoff (float) – Blocks with np.max(np.abs(block)) > cutoff are considered as zero. Defaults to QCUTOFF.


new_legcharges – A copy of the given legcharges with the None replaced by a compatible LegCharge. The new legcharge is ‘bunched’, but not sorted!

Return type

list of LegCharge

See also


similar functionality if the flat array is given by a ‘grid’.


detects the total charge, if all legs are known.