Python实现排列组合C(n,m) 和 A(n,m)

1. 从(0,1,2,3,4,5)5个数中随机选择2个数,有多少种选法?

这里用到了scipy库中的两个模块permutationcombination

(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

在这里插入图片描述

最后,注意一下排列组合的写法

C 5 2 C_{5}^{2} C52

在论文当中,一般写成

( 5 2 ) \binom{5}{2} (25)

注意一下两者的区别, C 5 2 C_{5}^{2} C52下大上小 ( 5 2 ) \binom{5}{2} (25)上大下小

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值