Python complete tutorial
  • Python Complete Tutorial
  • About this book
  • What you need to prepare
  • 1️⃣Try python for the first time
    • Install python
    • Hello world!
    • Hello world in a nutshell
    • The first simple python project
    • most useful libraries
    • Recommended websites
  • 2️⃣Data structure and basic operations
    • Python data structure
    • Data structure without hash table
    • Data structure with hash table
    • Variability and address
    • basic python programming
    • basic python programming 2
    • basic python programming 3
    • some additions
    • Fibonacci sequence
    • Judging prime numbers
    • txt/csv file operation
  • 🐍Practice program
    • 🚩fancy print
    • 🚩Remove duplicate elements
    • 🚩Palindrome detection
  • 😎leetcode
    • what is leetcode
  • 3️⃣Data mining and machine learning
    • What is data mining
    • iris data set
    • Mean median mode
    • Harmonic mean
    • Histogram
    • Correlation algorithm
    • Gaussian distribution data set
    • projection
    • PCA
    • MDS
    • Bayesian and Frequentist
    • Data normalization
    • binary SVM
    • One Hot Encoding
    • Multi-class SVM
    • Accuracy and error rate
    • Confusion matrix & Accuracy, Precision, Recall
    • F1 score
    • ROC and AUC
  • 4️⃣big data and data visualization
    • line chart
    • Parallel coordinates
    • Histogram chart
  • 5️⃣Mathematical algorithm and digital signal processing
    • Mathematical constants and basic operations
    • Normal distribution
    • Permutation and combination
    • Bernoulli distribution
    • Chaotic system
  • 6️⃣Classes and design patterns
    • Classes and design patterns
  • 7️⃣Operate the database with python
    • MySQL
      • Install MySQL
      • First try MySQL
      • MySQL Architecture
      • database operations
      • database
  • 8️⃣Cryptography
    • beginning of Cryptography
  • 9️⃣deep learning
    • What is Deep Learning
    • basic
  • 💔algorithm
    • Algorithms and Data Structures
Powered by GitBook
On this page
  • Combination
  • Permutation
  • Statistics
  1. Mathematical algorithm and digital signal processing

Permutation and combination

Permutation and combination

Permutation and combination are commonly used content in statistics.

It can be easily implemented in python through libraries.

Combination

import itertools
print( itertools.combinations(['tom',2,3,4], 3) )
print( list(itertools.combinations(['tom',2,3,4], 3)) )

get the following result

<itertools.combinations object at 0x000001BB837F6630>

[('tom', 2, 3), ('tom', 2, 4), ('tom', 3, 4), (2, 3, 4)]
>>> 

The result obtained with itertools can only see the address header position of the result.

If we convert the result to a list we can see the result.

The meaning of the above code is: regardless of the order, select three from ['tom', 2, 3, 4] without repetition

Implementing composition requires some specific algorithms, which we will explain in the leetcode section later.

Permutation

import itertools
print( itertools.permutations(['tom',2,3,4], 3) )
print( list(itertools.permutations(['tom',2,3,4], 3)) )

get the following result

<itertools.permutations object at 0x00000213DE0766D0>

[('tom', 2, 3), ('tom', 2, 4), ('tom', 3, 2), ('tom', 3, 4), 
('tom', 4, 2), ('tom', 4, 3), (2, 'tom', 3), (2, 'tom', 4), 
(2, 3, 'tom'), (2, 3, 4), (2, 4, 'tom'), (2, 4, 3), (3, 'tom', 2), 
(3, 'tom', 4), (3, 2, 'tom'), (3, 2, 4), (3, 4, 'tom'), (3, 4, 2), 
(4, 'tom', 2), (4, 'tom', 3), (4, 2, 'tom'), (4, 2, 3), (4, 3, 'tom'), 
(4, 3, 2)]
>>> 

The meaning of the above code is: consider the order, select three from ['tom', 2, 3, 4] without repetition

Permutation and combination are very useful in statistics and mathematics, such as in the Bernoulli distribution chapter.

Statistics

Start time of this page: January 7, 2022

Completion time of this page: January 9, 2022

PreviousNormal distributionNextBernoulli distribution

Last updated 3 years ago

5️⃣
Page cover image