3 examples of 'printing matrix in python' in Python

Every line of 'printing matrix in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
124def printmatrix(list):
125 """
126 Prints out a 2-dimensional list cleanly.
127 This is useful for debugging.
128
129 PARAMETERS
130 list - the 2D-list to display
131 """
132 # determine maximum length
133 maxlen = 0
134 colcount = len(list[0])
135 for col in list:
136 for cell in col:
137 maxlen = max(len(str(cell)), maxlen)
138 # print data
139 format = " %%%is |" % maxlen
140 format = "|" + format*colcount
141 for row in list:
142 print(format % tuple(row))
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

103def printMatrix(matrixP): #fancy matrices renderer for debugging
104 for row in matrixP:
105 for val in row:
106 print '{:4}'.format(val),
107 print
94def __repr__(self):
95
96 def format_row(row):
97 return "(%s)" % ", ".join(str(value) for value in row )
98
99 return "Matrix44(%s)" % \
100 ",".join(format_row(row) for row in self.rows())

Related snippets