helpers.axis_combinations

helpers.axis_combinations(arr, k, axis=0)

Generates all unique combinations of columns from the given array, selecting ‘k’ columns at a time.

Parameters

Name Type Description Default
arr numpy.numpy.ArrayLike A numpy ndarray required
k int The number of elements to include in each combination required
axis int Specified axis to obtain combinations. axis = 0 for row combinations, axis = 1 for column combinations. Defaults to 0. 0

Returns: List[npt.ArrayLike]: A list of arrays, each being a combination of ‘k’ elements from the original array. The combinations are returned as slices of the original array, not copies.

Examples:

import pyLHD
random_ls = pyLHD.LatinSquare(size = (4,4),seed = 1)
random_ls
array([[2, 3, 1, 2],
       [4, 2, 4, 4],
       [1, 4, 3, 3],
       [3, 1, 2, 1]])

Obtain all 2 column combinations of random_ls

pyLHD.axis_combinations(random_ls, k = 2, axis = 1)
[array([[2, 3],
        [4, 2],
        [1, 4],
        [3, 1]]),
 array([[2, 1],
        [4, 4],
        [1, 3],
        [3, 2]]),
 array([[2, 2],
        [4, 4],
        [1, 3],
        [3, 1]]),
 array([[3, 1],
        [2, 4],
        [4, 3],
        [1, 2]]),
 array([[3, 2],
        [2, 4],
        [4, 3],
        [1, 1]]),
 array([[1, 2],
        [4, 4],
        [3, 3],
        [2, 1]])]

Obtain all 2 row combinations of random_ls

pyLHD.axis_combinations(random_ls, k = 2, axis = 0)
[array([[2, 3, 1, 2],
        [4, 2, 4, 4]]),
 array([[2, 3, 1, 2],
        [1, 4, 3, 3]]),
 array([[2, 3, 1, 2],
        [3, 1, 2, 1]]),
 array([[4, 2, 4, 4],
        [1, 4, 3, 3]]),
 array([[4, 2, 4, 4],
        [3, 1, 2, 1]]),
 array([[1, 4, 3, 3],
        [3, 1, 2, 1]])]