Ask Your Question

Revision history [back]

To complete ppurka's answer, here is your code with corrections:

def ListM(p): 
    UT=[]
    for i1 in range(0,p): 
       for i2 in range(0,p): 
          for i3 in range(0,p):
             for i4 in range(0,p):
                UT=UT+[matrix([[i1,i2],[i3,i4]])]
    return UT

You may write the next to last line as follows (with the right indentation):

UT.append( matrix([[i1,i2],[i3,i4]]) )

Note that output of ListM(3) looks ugly, but this is a formatting "bug" when you display such a list, output is correct.

Good luck with Sage !

To complete ppurka's answer, here is your code with corrections:

def ListM(p): 
    UT=[]
    for i1 in range(0,p): range(p): 
       for i2 in range(0,p): range(p): 
          for i3 in range(0,p):
range(p):
             for i4 in range(0,p):
range(p):
                UT=UT+[matrix([[i1,i2],[i3,i4]])]
    return UT

You may write the next to last line as follows (with the right indentation):

UT.append( matrix([[i1,i2],[i3,i4]]) )

Note that output of ListM(3) looks ugly, but this is a formatting "bug" when you display such a list, output is correct.

Python has very nice syntax for "list comprehensions", you may write:

def rows(p):
    return [[x,y] for x in range(p) for y in range(p)]
def ListM(p): 
    return [matrix([r1,r2]) for r1 in rows(p) for r2 in rows(p)]

Of course in this case using MatrixSpace(GF(3),2,2) is definitely the right solution. Good luck with Sage !

To complete ppurka's answer, here is your code with corrections:

def ListM(p): 
    UT=[]
    for i1 in range(p): 
       for i2 in range(p): 
          for i3 in range(p):
             for i4 in range(p):
                UT=UT+[matrix([[i1,i2],[i3,i4]])]
    return UT

Note that output of ListM(3) looks ugly, but this is a formatting "bug" when you display such a list, output is correct.

Python has very nice syntax for "list comprehensions", you may write:

def rows(p):
    return [[x,y] for x in range(p) for y in range(p)]
def ListM(p): 
    return [matrix([r1,r2]) for r1 in rows(p) for r2 in rows(p)]

Of course in this case using MatrixSpace(GF(3),2,2)MatrixSpace(GF(p),2,2) is definitely the right solution. Good luck with Sage !