Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Combining sets with a matrix

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.

Combining sets with a matrix

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 rule 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.

Combining sets with a matrix

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 rule 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 A = matrix(ZZ, [[all(p[i] == 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 for i, u in (1..2) for v in (1..2) 
        if i <=j])
zip(ii, uu))
                     for p in P] for ii in S for uu in S])

Thanks for the help.

Combining sets with a matrix

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 P1 = cartesian_product([M]*2); S cartesian_product([M]*2) 
P1 = S.list()
P P.list()
P2 = cartesian_product([M]*4)
P P2 = [p for p in P P2 if p[0] <= p[1]]
C = P1 + P2 #len(C) total columns
R = P1*3  #len(R) total rows

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 SC and P in this order (which means 16 (16 columns) and which element the number of rows represents R. The rule it 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 rule 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.be:

A = matrix(ZZ, [[all(p[i] == u for i, u if (i,j) in zip(ii, uu))
                     for p R and [(i,j) in P] for ii C:
return -1
elif if (i,j) in S for uu R and [(i,u,j,v) in S])
C or (u,i,v,j) in C]:
return 1
else:
return 0

Combining sets with a matrix

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:

M = FiniteEnumeratedSet({1, 2})
P1 = cartesian_product([M]*2) 
P1 = P.list()
P2 = cartesian_product([M]*4)
P2 = [p for p in P2 if p[0] <= p[1]]
C = P1 + P2 #len(C) total columns
R = P1*3  #len(R) total rows

What I would like to do is to mount a matrix where the number of columns represents the sets C (16 columns) and the number of rows represents R. The rule for each entrance it will be:

if (i,j) in R and [(i,j) in C:
return -1
elif if (i,j) in R and [(i,u,j,v) in C or (u,i,v,j) in C]:
return 1
else:
return 0

Combining sets with a matrix

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:

M = FiniteEnumeratedSet({1, 2})
P1 = cartesian_product([M]*2) 
P1 = P.list()
P2 = cartesian_product([M]*4)
P2 = [p for p in P2 if p[0] <= p[1]]
C = P1 + P2 #len(C) total columns
R = P1*3  #len(R) total rows

What I would like to do is to mount a matrix where the number of columns represents the sets C (16 columns) and the number of rows represents R. The rule for each entrance it will be:

if (i,j) in R and [(i,j) in C:
 return -1
elif if (i,j) in R and [(i,u,j,v) in C or (u,i,v,j) in C]:
 return 1
else:
 return 0

Combining sets with a matrix

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:

M = FiniteEnumeratedSet({1, 2})
P1 = cartesian_product([M]*2) 
P1 = P.list()
P2 = cartesian_product([M]*4)
P2 = [p for p in P2 if p[0] <= p[1]]
C = P1 + P2 #len(C) total columns
R = P1*3  #len(R) total rows

What I would like to do is to mount a matrix where the number of columns represents the sets C (16 columns) and the number of rows represents R. The rule for each entrance it will be:

if (i,j) in R and [(i,j) (i,j) in C:
    return -1
elif if (i,j) in R and [(i,u,j,v) ((i,u,j,v) in C or (u,i,v,j) in C]:
C):
    return 1
else:
    return 0

Combining sets with a matrix

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:

M = FiniteEnumeratedSet({1, 2})
P1 = cartesian_product([M]*2) 
P1 = P.list()
P2 = cartesian_product([M]*4)
P2 = [p for p in P2 if p[0] <= p[1]]
C = P1 + P2 #len(C) total columns
R = P1*3  #len(R) total rows

What I would like to do is to mount a matrix where the number of columns represents the sets C (16 columns) and the number of rows represents R. The rule for each entrance it will be:

if (i,j) in R and (i,j) in C:
    return -1
elif if (i,j) in R and ((i,u,j,v) in C or (u,i,v,j) in C):
    return 1
else:
    return 0

I would like some output as it follows below:

                 (1,1) (1,2) (2,1) (2,2) (1,1) (1,2) (2,1) (2,2) (1,1) (1,2) (2,1) (2,2)
   (1, 1)        [-1     0     0     0     -1     0     0     0   -1     0     0     0] 
   (1, 2)        [ 0    -1     0     0      0    -1     0     0    0    -1     0     0]
   (2, 1)        [ 0     0    -1     0      0     0    -1     0    0     0    -1     0]
   (2, 2)        [ 0     0     0    -1      0     0     0    -1    0     0     0    -1]
   (1, 1, 1, 1)  [ 1     0     0     0      1     0     0     0    0     0     0     0] 
   (1, 1, 1, 2)  [ 1     1     0     0      0     0     0     0    0     0     0     0]
   (1, 1, 2, 1)  [ 0     0     0     0      1     0     0     0    0     0     0     0]
   (1, 1, 2, 2)  [ 0     1     0     0      0     0     0     0    0     0     0     0]
   (1, 2, 1, 1)  [ 0     0     0     0      0     0     0     0    1     0     0     0]
   (1, 2, 1, 2)  [ 0     0     1     1      0     0     0     0    1     0     0     1]
   (1, 2, 2, 1)  [ 0     0     1     0      0     1     0     0    0     1     0     0]
   (1, 2, 2, 2)  [ 0     0     0     1      0     1     0     0    0     1     0     0]
   (2, 2, 1, 1)  [ 0     0     0     0      0     0     1     0    0     0     1     0]
   (2, 2, 1, 2)  [ 0     0     0     0      0     0     1     1    0     0     0     0]