1
0

Minor code cleanup

This commit is contained in:
Niklas Birk 2024-02-22 02:28:26 +01:00
parent 3ec62d99f7
commit 3a4c0ed75d
3 changed files with 19 additions and 22 deletions

View File

@ -1,7 +1,6 @@
import math
import numpy
from numpy import linalg
class Matrix:
@ -76,8 +75,7 @@ class Matrix:
self.__shape__ = (len(data), len(data[0]))
self.__data__ = data
else:
raise ValueError(
"Only following signatures are allowed: "
raise ValueError("Only following signatures are allowed: "
"(list), (numpy.ndarray), (list, tuple), (list, str, int), (list, str, int, int), (str, int)")
def get_data(self):

View File

@ -34,9 +34,9 @@ print(f"vec_x2.T() has shape {vec_x2.T().shape()} | must be (1,10000)")
print(f"vec_x2.T().T() has shape {vec_x2.T().T().shape()} | must be (10000,1)")
print("End 1c\n")
### 1d addition and substraction
print("Start 1d addition and substraction")
# intitialization
### 1d addition and subtraction
print("Start 1d addition and subtraction")
# initialization
a = Vector([1, 3, 5, 7, 9])
b = Vector([-2, 5, 1, 0, -3])
# computation
@ -60,7 +60,7 @@ print("End 1d\n")
### 1e multiplication
print("Start 1e multiplication")
# intitialization
# initialization
a = Vector([1, 3, 5, 7, 9])
b = Vector([-2, 5, 1, 0, -3])
# computation with vectors
@ -77,9 +77,9 @@ y = 0.1 * b.T()
print(f"0.1 * b.T()= {str(y)} | must be {0.1 * np.array([-2, 5, 1, 0, -3])}")
print("End 1e\n")
### 1f divison
print("Start 1f divison")
# intitialization
### 1f division
print("Start 1f division")
# initialization
a = Vector([1, 3, 5, 7, 9])
b = Vector([-2, 5, 1, 7, -3])
# computation with vectors
@ -91,7 +91,7 @@ print("End 1f\n")
### 1g norm
print("Start 1g norm")
# intitialization
# initialization
a = Vector([1, 3, 5, 7, 9])
a_norm = a.norm()
a_normalized = a.normalize()
@ -101,7 +101,7 @@ print("End 1g\n")
### 1h negation
print("Start 1h negation")
# intitialization
# initialization
a = Vector([1, 3, 5, 7, 9])
x = -a
print(f"-a = {str(x)} | must be {-np.array([1, 3, 5, 7, 9])}")
@ -109,7 +109,7 @@ print("End 1h\n")
### 1i manipulation
print("Start 1i manipulation")
# intitialization
# initialization
a = Vector([1, 3, 5, 7, 9])
print(
f"a[{str([1, 2, 4])}] = {str(np.array(a[1, 2, 4]).reshape(3, ))} | must be {np.array([1, 3, 5, 7, 9]).reshape(5, 1)[np.array([1, 2, 4])].reshape(3, )}")
@ -148,8 +148,8 @@ print(f"A.T() has shape {A.T().shape()} | must be (3,4)")
print(f"A.T().T() has shape {A.T().T().shape()} | must be (4,3)")
print("End 2c\n")
### 1d addition and substraction
print("Start 2d addition and substraction")
### 1d addition and subtraction
print("Start 2d addition and subtraction")
# Initialization
A = Matrix(structure="diagonal", data=[3], offset=0, n=10)
print(str(A))
@ -186,8 +186,8 @@ print(
f"Norm of (B.T()*A.T() - np.(B.T()*A.T())) is {(B.T() * A.T() - Matrix(np.array(b_mat).T @ np.array(a_mat).T)).norm()} | must be < 1e-8")
print("End 2e\n")
### 1f divison
print("Start 2f divison")
### 1f division
print("Start 2f division")
# initialization
A = Matrix(a_mat)
# computation

View File

@ -274,4 +274,3 @@ class TestVector(TestCase):
expected = Vector([10, 2, 30, 4, 50, 6, 70, 8, 9])
self.assertEqual(expected, actual)