sympy.utilities.iterables.combinations() 替换? [英] sympy.utilities.iterables.combinations() with replacement?
问题描述
我正在尝试使用 sympy api 进行组合.
首先,组合没有替换 ...
from sympy.functions.combinatorial.numbers import nC从 sympy.utilities.iterables 导入组合nC('abc', 2)# >>>3列表(组合('abc',2))# >>>[('a', 'b'), ('a', 'c'), ('b', 'c')]
我现在想列出组合替换
nC('abc', 2, replacement=True)# >>>6
但是,combinations() 方法似乎不支持替换"参数?
初始化签名:组合(self,/, *args, **kwargs)文档字符串:组合(可迭代,r)-->组合对象返回迭代中元素的连续 r 长度组合.组合(范围(4),3)-->(0,1,2), (0,1,3), (0,2,3), (1,2,3)类型:类型
是另一种方法
<块引用><块引用>初始化签名:sympy.utilities.iterables.combinations_with_replacement(self,/, *args, **kwargs)文档字符串:
combinations_with_replacement(iterable, r) -->combinations_with_replacement 对象
返回迭代中元素的连续r长度组合允许单个元素连续重复.组合_with_replacement('ABC', 2) --> AA AB AC BB BC CC类型:类型
I'm experimenting with the sympy api for combinations.
First, combinations without replacement ...
from sympy.functions.combinatorial.numbers import nC
from sympy.utilities.iterables import combinations
nC('abc', 2)
# >>> 3
list(combinations('abc', 2))
# >>> [('a', 'b'), ('a', 'c'), ('b', 'c')]
I would now like to list the combinations with replacement
nC('abc', 2, replacement=True)
# >>> 6
However, the combinations() method doesn't seem to support a 'replacements' argument?
Init signature: combinations(self, /, *args, **kwargs)
Docstring:
combinations(iterable, r) --> combinations object
Return successive r-length combinations of elements in the iterable.
combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)
Type: type
It is a different method
Init signature: sympy.utilities.iterables.combinations_with_replacement(self, /, *args, **kwargs) Docstring:
combinations_with_replacement(iterable, r) --> combinations_with_replacement objectReturn successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats. combinations_with_replacement('ABC', 2) --> AA AB AC BB BC CC Type: type
这篇关于sympy.utilities.iterables.combinations() 替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!