generated from nullndr/pyproj
chore: add Matrix class
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from strings import *
|
||||
from tree import *
|
||||
from counter import *
|
||||
from matrix import *
|
||||
|
||||
def trees():
|
||||
t = build_tree((1,
|
||||
@@ -95,9 +96,13 @@ def counter():
|
||||
c.incr()
|
||||
assert c.val == 1
|
||||
|
||||
def matrix():
|
||||
m = Matrix([0, 1, 2, 3], [0, 4, 5, 6], [0, 7, 8, 9])
|
||||
print(m)
|
||||
print(transpose(m))
|
||||
|
||||
def main():
|
||||
counter()
|
||||
matrix()
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
19
src/matrix.py
Normal file
19
src/matrix.py
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
class Matrix:
|
||||
def __init__(self, *rows):
|
||||
self.rows = rows
|
||||
self.number_of_columns = len(rows[0])
|
||||
self.number_of_rows = len(rows)
|
||||
pass
|
||||
|
||||
def __repr__(self):
|
||||
return f"Matrix[{self.number_of_columns}x{self.number_of_rows}]{self.rows}"
|
||||
|
||||
def transpose(m):
|
||||
range_for_rows = range(m.number_of_rows)
|
||||
range_for_columns = range(m.number_of_columns)
|
||||
new_rows = [[None for x in range_for_rows] for x in range_for_columns]
|
||||
for i in range_for_columns:
|
||||
for j in range_for_rows:
|
||||
new_rows[i][j] = m.rows[j][i]
|
||||
return Matrix(*new_rows)
|
||||
Reference in New Issue
Block a user