1. 从(0,1,2,3,4,5)5个数中随机选择2个数,有多少种选法?
这里用到了scipy库中的两个模块permutation 和 combination
(1)选择分先后顺序,即 A 5 2 A_{5}^{2} A52
from scipy.special import perm, comb
print(perm(3, 2))
(2)选择不分先后顺序,即 C 5 2 C_{5}^{2} C52
from scipy.special import perm, comb
print(comb(5, 2))
2. 列出所有可能
C 5 2 C_{5}^{2} C52
from itertools import combinations
combins = [c for c in combinations(range(5), 2)]
print(combins)
A 5 2 A_{5}^{2} A52
from itertools import permutations
perms = permutations(range(5), 2)
perms