Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Add commas after matrix-element in matrix()

I want to replace the brackets, but to add commas after each matrix-element, except the last ones in the rows.

I get only the first part.

Is there an elementary way to add commas?

m = matrix([[0,0,1], [1,0,0]])
mymatrix =  m.str().replace('[', '').replace(']', '') # replace [, ]
#....  # add commas
print mymatrix

Out:

0 0 1
1 0 0

Add commas after matrix-element in matrix()

I want to replace the brackets, but to add commas after each matrix-element, except the last ones in the rows.

I get only the first part.

Is there an elementary way to add commas?

m = matrix([[0,0,1], [1,0,0]])
mymatrix =  m.str().replace('[', '').replace(']', '') # replace [, ]
#....  # add commas
print mymatrix

Out:Out Actual:

0 0 1
1 0 0

Out Target:

0, 0 ,1
1, 0, 0

Add commas after matrix-element in matrix()

I want to replace the brackets, but to add commas after each matrix-element, except the last ones in the rows.

I get only the first part.

Is there an elementary way to add commas?

m = matrix([[0,0,1], [1,0,0]])
mymatrix =  m.str().replace('[', '').replace(']', '') # replace [, ]
#....  # add commas
print mymatrix

Out Actual:

0 0 1
1 0 0

Out Target:

0, 0 ,1
0, 1
1, 0, 0

Add commas after matrix-element in matrix()

I want to replace the brackets, but to add commas after each matrix-element, except the last ones in the rows.

I get only the first part.

Is there an elementary way to add commas?

m = matrix([[0,0,1], [1,0,0]])
mymatrix =  m.str().replace('[', '').replace(']', '') # replace [, ]
#....  # add commas
print mymatrix

Out Actual:

0 0 1
1 0 0

Out Target:

0, 0, 1
1, 0, 0

Add commas after matrix-element matrix-elements in matrix()

I want to replace the brackets, but to add commas after each matrix-element, except the last ones in the rows.

I get only the first part.

Is there an elementary way to add commas?

m = matrix([[0,0,1], matrix([[2222,333,44444], [1,0,0]])
mymatrix =  m.str().replace('[', '').replace(']', '') # replace [, ]
#....  # add commas
print mymatrix

Out Actual:

 2222   333 44444
    1     0 0 1
1 0  0

Out Target:

 2222,   333, 44444
    1,     0, 0, 1
1, 0,  0

Add commas after matrix-elements in matrix()

I want to replace the brackets, but to add commas after each matrix-element, except the last ones in the rows.

I get only the first part.

Is there an elementary way to add commas?commas to the sage-matrix?
Because matrix() has the great advantage that the elements are aligned in all cases.

m = matrix([[2222,333,44444], [1,0,0]])
mymatrix =  m.str().replace('[', '').replace(']', '') # replace [, ]
#....  # add commas
print mymatrix

Out Actual:

 2222   333 44444
    1     0     0

Out Target:

 2222,   333, 44444
    1,     0,     0