# contract¶

tenpy.algorithms.network_contractor.contract(tensor_list, tensor_names=None, leg_contractions=None, open_legs=None, sequence=None)[source]

Contract a network of tensors.

Based on the MatLab function `ncon.m` as described in arXiv:1402.0939.

Parameters
• tensor_list (list of `Array`) – The tensors to be contracted.

• leg_contractions (list of `[n1, l1, n2, l2]`) – A list of contraction instructions. An entry of leg_contractions has the form `[n1, l1, n2, l2]`, where `n1, n2` are entries of tensor_names and each identify an `Array` in tensor_list. `l1, l2` are leg labels of the corresponding `Array`. The instruction implies to contract leg `l1` of tensor `n1` with leg `l2` of tensor `n2`.

• open_legs (list of `[n1, l1, l]`) – A list of instructions for “open” (uncontracted) legs. `[n1, l1, l]` implies that leg `l1` of tensor `n1` is not contracted and is labelled `l` in the result.

• tensor_names (list of str) – A list of names for each tensor, to be used in leg_contractions and open_legs. The default value is list(range(len(tensor_list))), so that the tensor “names” are `0, 1, 2, ...`.

• sequence (list of int) – The order in which the leg_contractions are to be performed. An entry of network_contractor.outer_product indicates performing an outer product. This corresponds to the zero-in-sequence convention of arXiv:1304.6112

Returns

result – The number or tensor resulting from the contraction.

Return type

`Array` | complex