| 1 | initial version |
I think you should continue to manipulate m.str(), but using regular expressions, since m.str() already has the correct spacing. The following will work if you know that the matrix entries will be numbers (plus a possible decimal point and/or minus sign), no letters:
m = matrix([[2222,333,44444], [1,0,0]])
no_brackets = m.str().replace('[', '').replace(']', '') # replace [, ]
add_commas = re.sub("([-.0-9]+) ", "\\1, ", no_brackets)
print(add_commas)
Output:
2222, 333, 44444
1, 0, 0
| 2 | No.2 Revision |
I think you should continue to manipulate m.str(), but using regular expressions, since m.str() already has the correct spacing. The following will work if you know that the matrix entries will be numbers (plus a possible decimal point and/or minus sign), no letters:
import re
m = matrix([[2222,333,44444], [1,0,0]])
no_brackets = m.str().replace('[', '').replace(']', '') # replace [, ]
add_commas = re.sub("([-.0-9]+) ", "\\1, ", no_brackets)
print(add_commas)
Output:
2222, 333, 44444
1, 0, 0
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.