python的combinations_with_replacement这个函数 MMA怎么实现?
mathematica吧
全部回复
仅看楼主
level 7
igs816 楼主
combinations_with_replacement(iterable, r)
返回iterable中所有长度为r的子序列,返回的子序列中的项按输入iterable中的顺序排序,带重复
combinations_with_replacement([1, 2, 3], 2)
输出:
(1, 1)(1, 2)(1, 3)(2, 2)(2, 3)(3, 3)
2017年12月28日 15点12分 1
吧务
level 12
2017年12月29日 00点12分 2
吧务
level 12
然后提供一个简单点的写法。虽然速度比上面链接里的那个差一点
combWithRep[list_List, k_Integer] :=
list[[# - Range[0, k - 1]]] & /@ Subsets[Range[Length[list] + k - 1], {k}]
2017年12月29日 01点12分 3
感谢
2017年12月29日 02点12分
1