Getting ready for Testing
This commit is contained in:
@@ -0,0 +1 @@
|
||||
tabulate==0.9.0
|
||||
@@ -0,0 +1,16 @@
|
||||
## Compute.py
|
||||
### Functions:
|
||||
**matmul(matrix_a, matrix_b):**
|
||||
|
||||
Multipliziert zwei Matrizen miteinander und gibt das Produkt als neue Matrix zurück.
|
||||
Wirft einen ValueError, wenn die Matrizen aufgrund unpassender Dimensionen nicht multiplizierbar sind.
|
||||
|
||||
**transpose(matrix):**
|
||||
|
||||
Gibt die Transponierte einer gegebenen Matrix zurück (Zeilen und Spalten werden vertauscht).
|
||||
Überprüft, ob die Matrix leer oder fehlerhaft aufgebaut ist, und wirft in diesem Fall einen ValueError.
|
||||
|
||||
**rot_2D(angle):**
|
||||
|
||||
Erzeugt eine 2D-Rotationsmatrix für einen gegebenen Winkel (in Grad).
|
||||
Diese Matrix kann verwendet werden, um Punkte in der Ebene um den Ursprung zu rotieren.
|
||||
@@ -0,0 +1 @@
|
||||
from .compute import matmul, transpose, rot_2D
|
||||
@@ -0,0 +1,80 @@
|
||||
from typing import List
|
||||
import math
|
||||
from tabulate import tabulate
|
||||
|
||||
def matmul(matrix_a: List[List[int]], matrix_b: List[List[int]]) -> List[List[int]]:
|
||||
"""
|
||||
Matrix multiplication
|
||||
:param matrix_a: Matrix A
|
||||
:param matrix_b: Matrix B
|
||||
:return: product of matrix_a and matrix_b
|
||||
:raises: ValueError: wenn Matrix A and Matrix B nicht multipliezierbar sind
|
||||
"""
|
||||
|
||||
if len(matrix_a[0]) != len(matrix_b):
|
||||
print(len(matrix_a[0]))
|
||||
print(len(matrix_b))
|
||||
raise ValueError("Matrix kann nicht multipliziert werden")
|
||||
|
||||
ergebnis1 = []
|
||||
ergebnis2 = []
|
||||
result = 0
|
||||
spalte_max = len(matrix_b[0])
|
||||
zeile = 0
|
||||
|
||||
for spalte in range(len(matrix_a)):
|
||||
for zeile in range(spalte_max):
|
||||
for z in range(len(matrix_a[0])):
|
||||
zahl = matrix_a[spalte][z] * matrix_b[z][zeile]
|
||||
result = result + zahl
|
||||
ergebnis1.append(result)
|
||||
result = 0
|
||||
ergebnis2.append(ergebnis1)
|
||||
ergebnis1 = []
|
||||
|
||||
return ergebnis2
|
||||
|
||||
def transpose(matrix: list[list[int]]) -> list[list[int]]:
|
||||
"""
|
||||
Transpose a matrix
|
||||
:param matrix: valid matrix
|
||||
:return: transpose of matrix
|
||||
"""
|
||||
if len(matrix) == 0:
|
||||
raise ValueError("Matrix leer")
|
||||
mindest_länge = len(matrix[0])
|
||||
for zeile in range(len(matrix)):
|
||||
if len(matrix[zeile]) != mindest_länge :
|
||||
raise ValueError("Matrix falsch")
|
||||
|
||||
anzahl_spalten= len(matrix)
|
||||
anzahl_zeilen= len(matrix[0])
|
||||
ergebnis1 = []
|
||||
ergebnis2 = []
|
||||
for z in range(anzahl_zeilen):
|
||||
for s in range(anzahl_spalten):
|
||||
ergebnis1.append(matrix[s][z])
|
||||
|
||||
ergebnis2.append(ergebnis1)
|
||||
ergebnis1 = []
|
||||
|
||||
return ergebnis2
|
||||
|
||||
|
||||
def rot_2D(angle: int) -> List[List[float]]:
|
||||
"""
|
||||
Rotation matrix
|
||||
:param angle: any angle in degrees
|
||||
:return: rotation matrix
|
||||
"""
|
||||
zahl1 = math.cos(math.radians(angle))
|
||||
zahl2 = -math.sin(math.radians(angle))
|
||||
zahl3 = math.sin(math.radians(angle))
|
||||
zahl4 = math.cos(math.radians(angle))
|
||||
|
||||
return [[zahl1, zahl2], [zahl3, zahl4]]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
"alles selbst gemacht"
|
||||
print(rot_2D())
|
||||
@@ -0,0 +1,17 @@
|
||||
[project]
|
||||
name = "matrixmania_marcel"
|
||||
version = "0.1.0"
|
||||
description = "MatrixMania: Simple linear algebra functions for teaching (matmul, transpose, rot_2D)."
|
||||
|
||||
authors = [
|
||||
{ name="Dein Name", email="deine.mail@th-nuernberg.de" }
|
||||
]
|
||||
readme = "README.md"
|
||||
license = { text = "MIT" }
|
||||
requires-python = ">=3.7"
|
||||
dependencies = ["tabulate"]
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["matrixmania"]
|
||||
Reference in New Issue
Block a user