toqito.perms.perfect_matchings

Perfect matchings refers to ways of grouping an even number of objects into pairs.

Module Contents

toqito.perms.perfect_matchings.perfect_matchings(num)[source]

Give all perfect matchings of num objects.

The input can be either an even natural number (the number of objects to be matched) or a numpy array containing an even number of distinct objects to be matched.

Returns all perfect matchings of a given list of objects. That is, it returns all ways of grouping an even number of objects into pairs.

This function is adapted from QETLAB. [@QETLAB_link].

Examples

This is an example of how to generate all perfect matchings of the numbers 0, 1, 2, 3.

```python exec=”1” source=”above” from toqito.perms import perfect_matchings

print(perfect_matchings(4)) ```

Parameters:
  • num (list[int] | int | numpy.ndarray) – Either an even integer, indicating that you would like all perfect matchings of the integers 0, 1, … N-1,

  • entries (or a list or np.array containing an even number of distinct)

  • all (indicating that you would like)

  • entries. (perfect matchings of those)

Returns:

An array containing all valid perfect matchings of size num.

Return type:

numpy.ndarray