perms.perfect_matchings
¶
Perfect matchings.
Module Contents¶
Functions¶
|
Give all perfect matchings of |
- perms.perfect_matchings.perfect_matchings(num)¶
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. [1].
Examples
This is an example of how to generate all perfect matchings of the numbers 1, 2, 3, 4.
>>> from toqito.perms import perfect_matchings >>> perfect_matchings(4) array([[1, 2, 3, 4], [1, 3, 2, 4], [1, 4, 3, 2]])
References
[1]Nathaniel Johnston. QETLAB: A MATLAB toolbox for quantum entanglement. https://github.com/nathanieljohnston/QETLAB. doi:10.5281/zenodo.44637.
- Parameters:
num (list[int] | int | numpy.ndarray) – Either an even integer, indicating that you would like all perfect matchings of the integers 1,2, … N, or a list or np.array containing an even number of distinct entries, indicating that you would like all perfect matchings of those entries.
- Returns:
An array containing all valid perfect matchings of size
num
.- Return type:
numpy.ndarray