Factorial, Permutation, Combination
The number of ways we can arrange distinct objects is given by:
The number of ways we can arrange 5 distinct objects is:
Syntax for factorial:
import numpy as np
np.math.factorial(n)
The number of ways we can arrange distinct objects, taking them at a time is given by:
import numpy as np
np.math.factorial(n)/np.math.factorial(n-r)
The number of distinct combinations of distinct objects that can be formed by taking at a time is given by:
import numpy as np
np.math.factorial(n)/(np.math.factorial(r)*np.math.factorial(n-r))
Example: For and , compute the following:
import numpy as np
np.math.factorial(6)
Show expected output
720Interpretation: 6!=720. There 720 different arrangement of 6 distinct objects.
import numpy as np
np.math.factorial(6)/np.math.factorial(6-3)
Show expected output
120.0Interpretation: there are 120 permutations of 6 objects taking 3 at a time.
import numpy as np
np.math.factorial(6)/(np.math.factorial(3)*np.math.factorial(6-3))
Show expected output
20.0Interpretation: There are 20 combinations (without regard to order) of 6 objects taking 3 at a time.
Adapted from Python for Introductory Statistics, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.