次の種類の構造/エントリを持つ配列を使用しています(量子情報ゲームのマスタープロジェクト用); 1 列目のエントリ{0,1}
、2 列目{0,1}
、3 列目{0,2**(d-1)}
、最後の列{0,d-1}
。については次のとおりですd=3
。
G =
[[0 0 0 0]
[0 0 0 1]
[0 0 0 2]
[0 0 1 0]
[0 0 1 1]
[0 0 1 2]
[0 0 2 0]
[0 0 2 1]
[0 0 2 2]
[0 0 3 0]
[0 0 3 1]
[0 0 3 2]
[0 1 0 0]
[0 1 0 1]
[0 1 0 2]
[0 1 1 0]
[0 1 1 1]
[0 1 1 2]
[0 1 2 0]
[0 1 2 1]
[0 1 2 2]
[0 1 3 0]
[0 1 3 1]
[0 1 3 2]
[1 0 0 0]
[1 0 0 1]
[1 0 0 2]
[1 0 1 0]
[1 0 1 1]
[1 0 1 2]
[1 0 2 0]
[1 0 2 1]
[1 0 2 2]
[1 0 3 0]
[1 0 3 1]
[1 0 3 2]
[1 1 0 0]
[1 1 0 1]
[1 1 0 2]
[1 1 1 0]
[1 1 1 1]
[1 1 1 2]
[1 1 2 0]
[1 1 2 1]
[1 1 2 2]
[1 1 3 0]
[1 1 3 1]
[1 1 3 2]]
次の関数を使用して、この配列を構築しています。
def games(d = 3):
res = np.empty(0).astype(int)
for a in range(2):
for b in range(2):
for x in range(2**(d-1)):
for y in range(d):
res = np.append(res,[a,b,x,y],axis=0)
res = np.reshape(res,(-1,4))
return res
今私ができるようにしたいのは、列のエントリがカウントを開始する順序を簡単に選択することです。(上段右列から左列)
たとえば、1 列目からカウントを開始し、次に 3 列目、4 列目、最後に 2 列目とします。for-loops
関数内を並べ替えることでこれを取得できます。
def games(d = 3):
res = np.empty(0).astype(int)
for b in range(2):
for y in range(d):
for x in range(2**(d-1)):
for a in range(2):
res = np.append(res,[a,b,x,y],axis=0)
res = np.reshape(res,(-1,4))
return res
これにより、次のことが得られます。
G=
[[0 0 0 0]
[1 0 0 0]
[0 0 1 0]
[1 0 1 0]
[0 0 2 0]
[1 0 2 0]
[0 0 3 0]
[1 0 3 0]
[0 0 0 1]
[1 0 0 1]
[0 0 1 1]
[1 0 1 1]
[0 0 2 1]
[1 0 2 1]
[0 0 3 1]
[1 0 3 1]
[0 0 0 2]
[1 0 0 2]
[0 0 1 2]
[1 0 1 2]
[0 0 2 2]
[1 0 2 2]
[0 0 3 2]
[1 0 3 2]
[0 1 0 0]
[1 1 0 0]
[0 1 1 0]
[1 1 1 0]
[0 1 2 0]
[1 1 2 0]
[0 1 3 0]
[1 1 3 0]
[0 1 0 1]
[1 1 0 1]
[0 1 1 1]
[1 1 1 1]
[0 1 2 1]
[1 1 2 1]
[0 1 3 1]
[1 1 3 1]
[0 1 0 2]
[1 1 0 2]
[0 1 1 2]
[1 1 1 2]
[0 1 2 2]
[1 1 2 2]
[0 1 3 2]
[1 1 3 2]]
関数内の for ループの順序を並べ替えることはできますが、すべての並べ替えをカバーするには 24 の異なるケースを作成する必要があります。一般的に、より良いものは何でしょうsolution/approach
か?