Ask Your Question

Revision history [back]

Maybe the following does what you want?

sage: p = dict() sage: P = Permutations(3) sage: for i in (1 .. 3): ....: for u in (1 .. 3): ....: p[i, u] = [1 if P[m][i-1] == u else 0 for m in (0 .. 5)]

Usage:

sage: p
{(1, 1): [1, 1, 0, 0, 0, 0],
 (1, 2): [0, 0, 1, 1, 0, 0],
 (1, 3): [0, 0, 0, 0, 1, 1],
 (2, 1): [0, 0, 1, 0, 1, 0],
 (2, 2): [1, 0, 0, 0, 0, 1],
 (2, 3): [0, 1, 0, 1, 0, 0],
 (3, 1): [0, 0, 0, 1, 0, 1],
 (3, 2): [0, 1, 0, 0, 1, 0],
 (3, 3): [1, 0, 1, 0, 0, 0]}

sage: p[2, 3]
[0, 1, 0, 1, 0, 0]

Maybe the following does what you want?

sage: p = dict()
sage: P = Permutations(3)
sage: for i in (1 .. 3):
....:     for u in (1 .. 3):
....:         p[i, u] = [1 if P[m][i-1] == u else 0 for m in (0 .. 5)]

5)]

Usage:

sage: p
{(1, 1): [1, 1, 0, 0, 0, 0],
 (1, 2): [0, 0, 1, 1, 0, 0],
 (1, 3): [0, 0, 0, 0, 1, 1],
 (2, 1): [0, 0, 1, 0, 1, 0],
 (2, 2): [1, 0, 0, 0, 0, 1],
 (2, 3): [0, 1, 0, 1, 0, 0],
 (3, 1): [0, 0, 0, 1, 0, 1],
 (3, 2): [0, 1, 0, 0, 1, 0],
 (3, 3): [1, 0, 1, 0, 0, 0]}

sage: p[2, 3]
[0, 1, 0, 1, 0, 0]

Maybe the following does what you want?

sage: p = dict()
sage: P = Permutations(3)
sage: for i in (1 .. 3):
....:     for u in (1 .. 3):
....:         p[i, u] = [1 if P[m][i-1] == u else 0 for m in (0 .. 5)]

Usage:

sage: p
{(1, 1): [1, 1, 0, 0, 0, 0],
 (1, 2): [0, 0, 1, 1, 0, 0],
 (1, 3): [0, 0, 0, 0, 1, 1],
 (2, 1): [0, 0, 1, 0, 1, 0],
 (2, 2): [1, 0, 0, 0, 0, 1],
 (2, 3): [0, 1, 0, 1, 0, 0],
 (3, 1): [0, 0, 0, 1, 0, 1],
 (3, 2): [0, 1, 0, 0, 1, 0],
 (3, 3): [1, 0, 1, 0, 0, 0]}

sage: p[2, 3]
[0, 1, 0, 1, 0, 0]

Note that you could replace

p[i, u] = [1 if P[m][i-1] == u else 0 for m in (0 .. 5)]

by

p[i, u] = [Integer(P[m][i-1] == u) for m in (0 .. 5)]