Last active
December 19, 2018 13:41
-
-
Save RodrigoCMoraes/b8cc0be6259db787915419858c2a0734 to your computer and use it in GitHub Desktop.
Pairwise indexes from 1D array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pairwise_indexes(array, mode='comb'): | |
""" | |
Get indexes pairwise from array | |
Params: | |
array(list or numpy.array): array with shape(N,) where N is array size | |
mode: comb=combinatations or perm=permutations | |
Returns: | |
pairs(numpy.array): array with pair elements | |
""" | |
import itertools as it | |
import numpy as np | |
array = np.array(array) | |
if mode == 'comb': | |
pairs = list(it.combinations(array, 2)) | |
elif mode == 'perm': | |
pairs = list(it.permutations(array, 2)) | |
pairs = np.array(pairs) | |
return pairs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment