1
0

Finalize vector.py

This commit is contained in:
2024-01-13 13:53:21 +01:00
parent 15fb2d096e
commit 71f6c19f51
3 changed files with 57 additions and 63 deletions

View File

@@ -114,9 +114,9 @@ class Matrix:
if isinstance(other, Matrix):
if self.__shape__ != other.__shape__:
raise ValueError("The shape of the operands must be the same")
return self.__data__ + other.__data__
return Matrix(self.__data__ + other.__data__)
elif isinstance(other, int) or isinstance(other, float):
return self.__data__ + other
return Matrix(self.__data__ + other)
else:
raise ValueError("Only a number or another ``Matrix`` can be added to a ``Matrix``")
@@ -145,7 +145,7 @@ class Matrix:
def __truediv__(self, other):
if isinstance(other, int) or isinstance(other, float):
return self.__data__ / other
return Matrix(self.__data__ / other)
else:
raise ValueError("A ``Matrix`` can only be divided ba a number")
@@ -172,4 +172,3 @@ class Matrix:
def __setitem__(self, key, value):
self.__data__[key] = value