-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.py
More file actions
executable file
·33 lines (24 loc) · 796 Bytes
/
Matrix.py
File metadata and controls
executable file
·33 lines (24 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Matrix(object):
"""A simple Matrix class in Python"""
def __init__(self, rows, columns):
self.width = columns
self.height = rows
self.data = []
# self.data = [[0] * columns] * rows
for i in range(self.height):
self.data.append([])
for j in range(self.width):
self.data[i].append(0)
def setElementAt(self, x, y, value):
self.data[x][y] = value
def getElementAt(self, x, y):
return self.data[x][y]
def __str__(self):
result = []
for row in self.data:
for cell in row:
result.append(str(cell))
result.append(" ")
result.append("\n")
string = ''.join(result)
return string