设v = {x: x in {-1,0,1}}使|v| = 9的维数
向量x中的每个元素都可以采用3、可能值、-1,0或1。
如何生成向量v的所有可能组合?
Example: v= {1,0,0,0,1,1,0},v= {-1,0,0,-1,1,0,0,1,0}等
我会有3^9组合吗?
谢谢。
发布于 2014-02-13 17:52:40
如果您正在使用python,您可以简单地这样做:
import itertools
v = itertools.product([-1,0,1], repeat=9)
# v will be a generator
# to have the whole list as tuples
list_v = list(v)
# Verify the number of combination
print len(list(v))它给你的是: 19683,或3^9
https://stackoverflow.com/questions/21761446
复制相似问题