# created by ChatGPT from typing import List import math from tabulate import tabulate Matrix = List[List[float]] def matmul(matrix_1: Matrix, Matrix_2: Matrix) -> Matrix: #alles klein HeightA = len(matrix_1) HeightB = len(Matrix_2) if HeightA == 0 or HeightB == 0: raise ValueError("Matrizen dürfen nicht leer sein") WidthA = len(matrix_1[0]) WidthB = len(Matrix_2[0]) if WidthA != HeightB: raise ValueError("Multiplikation der Matrizen nicht zulässig (Spalten A != Zeilen B)") Matrix_3 = [[0.0 for _ in range(WidthB)] for _ in range(HeightA)] for i in range(HeightA): for j in range(WidthB): for k in range(WidthA): Matrix_3[i][j] += matrix_1[i][k] * Matrix_2[k][j] return Matrix_3 def transpose(matrix: Matrix) -> Matrix: if not matrix: raise ValueError("Matrix darf nicht leer sein") rows = len(matrix) cols = len(matrix[0]) if not all(len(row) == cols for row in matrix): raise ValueError("Matrix hat ungleichmäßige Zeilenlängen") transposed_matrix = [[0.0 for _ in range(rows)] for _ in range(cols)] for i in range(rows): for j in range(cols): transposed_matrix[j][i] = matrix[i][j] return transposed_matrix def rot_2D(angle_degrees: float) -> Matrix: angle_radians = math.radians(angle_degrees) cos_theta = math.cos(angle_radians) sin_theta = math.sin(angle_radians) rotation_matrix = [ [cos_theta, -sin_theta], [sin_theta, cos_theta] ] return rotation_matrix if __name__ == "__main__": matrix = [[1,2,3], [2,3,4]] print("Matrix A:") print(tabulate(matrix))