Initial
This commit is contained in:
0
src/main.py
Normal file
0
src/main.py
Normal file
2
src/matrix.py
Normal file
2
src/matrix.py
Normal file
@ -0,0 +1,2 @@
|
||||
class Matrix:
|
||||
|
46
src/vector.py
Normal file
46
src/vector.py
Normal file
@ -0,0 +1,46 @@
|
||||
class Vector:
|
||||
__data__ = []
|
||||
|
||||
def __init__(self, data):
|
||||
if isinstance(data, list):
|
||||
self.__data__ = data
|
||||
elif isinstance(data, int):
|
||||
self.__init__([0] * data)
|
||||
else:
|
||||
raise ValueError("data must be a list or an integer for dimension")
|
||||
|
||||
def get_data(self):
|
||||
return self.__data__
|
||||
|
||||
def get_dimension(self):
|
||||
return len(self.__data__)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.__data__)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__data__ == other.__data__
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.__data__}"
|
||||
|
||||
def __add__(self, other):
|
||||
if self.get_dimension() != other.get_dimension():
|
||||
raise ValueError("The vectors to be added must have the same dimension")
|
||||
|
||||
data = []
|
||||
for (i, j) in zip(self, other):
|
||||
data.append(i + j)
|
||||
|
||||
return Vector(data)
|
||||
|
||||
def __mul__(self, other):
|
||||
if isinstance(other, Vector):
|
||||
...
|
||||
elif isinstance(other, int) or isinstance(other, float):
|
||||
...
|
||||
else:
|
||||
raise ValueError("A vector can only be multiplied with an vector (dot product) or a scalar")
|
||||
|
||||
def __rmul__(self, other):
|
||||
return self * other
|
Reference in New Issue
Block a user