Hello, I hope everyone is doing fine. I try to do some combinations of sets, but I have no clue how. If anyone can point me in any direction, it will be great. Here is the problem:
p = dict()
M = FiniteEnumeratedSet({1, 2})
S = cartesian_product([M]*2); S = S.list()
P = cartesian_product([M]*4)
P = [p for p in P if p[0] <= p[1]]
Then S
give me the list [(1, 1), (1, 2), (2, 1), (2, 2)]
and P
give me the list (both in lexicographical order)
[(1, 1, 1, 1), (1, 1, 1, 2), (1, 1, 2, 1), (1, 1, 2, 2), (1, 2, 1, 1), (1, 2, 1, 2), (1, 2, 2, 1),
(1, 2, 2, 2), (2, 2, 1, 1), (2, 2, 1, 2), (2, 2, 2, 1), (2, 2, 2, 2)]
What I would like to do is to mount a matrix where the number of columns represents the sets S
and P
in this order (which means 16 columns) and which element will be determined by the rule:
for m in range(len(P))
put 1 for
s in S and p in P ifs[0]==P[m][0]
and s[1]==P[m][2]
or s[0]==P[m][1]
and s[1]==P[m][3]
. Then put -1
in all columns corresponding to S that satisfies this role and fill the remaining entries of the matrix with0
.
I've tried something like below, but it is not working, and it is not exactly what I need.
for i in (1 .. 2):
for j in (1..2):
for u in (1 .. 2):
for v in (1..2):
if i <= j:
p[i,j, u,v] = [1 for s in P if s[0]==s[2] or s[1]==s[3] else 0 for m in (0 .. 11)]
A = matrix([p[i,j,u,v] for i in (1..2) for j in (1..2) for u in (1..2) for v in (1..2)
if i <=j])
Thanks for the help.