itertools.combinations() 是确定性的吗?
Is itertools.combinations() deterministic?
从 itertools.combinations() 中获得的项目的顺序是确定性的吗?
我目前正在编写一个脚本,该脚本使用 itertools.combinations 生成过多的对象,大到我无法将它们全部保留在内存中。对于每个组合,都有一个函数 returns 我将一个值存储在一个 numpy 数组中(因为它们的内存效率相当高)。我的内存几乎不足以存储所有这些浮点数。
然后我遍历那些浮点数,如果它是一个感兴趣的索引,我再次 运行 itertools.combinations 使用计数器变量来访问产生该结果的组合(只需要几个秒)。
我已经用我有足够内存的各种较小的数据集对此进行了测试,并且在这些情况下条目都是相同的,但我担心这不是 "safe" 做我的事情的方法想要.
来自docs:
Combinations are emitted in lexicographic sort order. So, if the input
iterable is sorted, the combination tuples will be produced in sorted
order.
Elements are treated as unique based on their position, not on their
value. So if the input elements are unique, there will be no repeat
values in each combination.
从 itertools.combinations() 中获得的项目的顺序是确定性的吗?
我目前正在编写一个脚本,该脚本使用 itertools.combinations 生成过多的对象,大到我无法将它们全部保留在内存中。对于每个组合,都有一个函数 returns 我将一个值存储在一个 numpy 数组中(因为它们的内存效率相当高)。我的内存几乎不足以存储所有这些浮点数。
然后我遍历那些浮点数,如果它是一个感兴趣的索引,我再次 运行 itertools.combinations 使用计数器变量来访问产生该结果的组合(只需要几个秒)。
我已经用我有足够内存的各种较小的数据集对此进行了测试,并且在这些情况下条目都是相同的,但我担心这不是 "safe" 做我的事情的方法想要.
来自docs:
Combinations are emitted in lexicographic sort order. So, if the input iterable is sorted, the combination tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their value. So if the input elements are unique, there will be no repeat values in each combination.