permuter#

pybear.utilities.permuter(vector_of_vectors)#

Find all possible unique combinations in drawing a single value from each group in a collection of groups of unique values.

Given a vector of length n that contains n vectors of unique values with lengths (l1, l2,…ln), and whose total possible number of unique combinations is pn, generate an array of shape (pn, n) that contains in its rows the index positions given by permuting through all possible unique combinations of values when drawing a single value from each of those vectors.

Parameters:
vector_of_vectorsSequence[Sequence[Any]]

Vector of vectors of non-zero length

Returns:
permutationslist of shape (n_combinations, n_vectors)

An array that contains in its rows the index positions of all possible unique combinations of values in drawing a single value from each group in a collection of groups of unique values.

See also

itertools.product

for another implementation that returns values instead of indices.

Examples

>>> from pybear.utilities import permuter
>>> vector1 = ['a', 'b', 'c']
>>> vector2 = ['w', 'x']
>>> vector3 = ['y', 'z']
>>> vector_of_vectors = [vector1, vector2, vector3]
>>> for _tuple in permuter(vector_of_vectors):
...     print(_tuple)
(0, 0, 0)
(0, 0, 1)
(0, 1, 0)
(0, 1, 1)
(1, 0, 0)
(1, 0, 1)
(1, 1, 0)
(1, 1, 1)
(2, 0, 0)
(2, 0, 1)
(2, 1, 0)
(2, 1, 1)