프로그래머의 삶 Programmer's Life/Python, Numpy, Pandas

permutations, product, combination by itertools library

Oliver's World 2022. 6. 9. 18:20
728x90

Let me show the easy-peasy 3 functions of the itertools library below. 

아래에서 굉장히 쉽게 사용 가능한 itertools 라이브러리의 3가지 기능을 보여드리겠습니다.

 

Although there's based on normal distribution, sometimes we want to know the possibility of the outcomes.

(In spite of the outcomes being a statistically right and the very small possibility of unexpected results, we need recognize the long-tail events because such events result in tremendous shock)

통계적 확률은 정규 분포를 기반으로 서술됨에도 불구하고 우리는 통계적 결과의 가능성을 알고 싶어합니다.

(결과가 통계적으로 맞고 예상치 못한 결과가 나올 가능성이 매우 적음에도 불구하고, ㅇ롱테일 이벤트는 엄청난 충격을 주기 때문에 주의가 필요합니다.)

 

num = {1, 2, 3, 4, 5}
# accept overlapping - result of each set consists of 3 elements
A = set(itertools.product(num, num, num))
# permutation
B = set(itertools.permutations(num, 3))
# combination
C = set(itertools.combinations(num, 3))

 

num is an array that consists of 5 elements. 

num은 5개의 요소로 구성된 배열입니다.

 

A, B, and C are the set for each result of functions; product, permutations, and combinations. 

A, B, C는 함수의 num 배열요소로서 생성 가능한 각 결과에 대한 집합입니다. 

(A - 중복허용 / B - 순열 / C - 조합)

 

 

Here are the results of each function.

해당 함수별 결과 집합의 총 갯수입니다. (A-125 / B-60 / C-10)

결과

 

728x90