From 4272fa33c85f4dcfb952e6344ff7702697697102 Mon Sep 17 00:00:00 2001 From: laura Date: Wed, 28 Oct 2026 21:54:28 +0100 Subject: [PATCH] =?UTF-8?q?Requirements=20hinzugef=C3=BCgt=20und=20Code=20?= =?UTF-8?q?mit=20Ruff=20=C3=BCberpr=C3=BCft?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compute.py | 21 +++++++++++++-------- pyproject.toml | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/compute.py b/compute.py index dc7f6d0..25843c4 100644 --- a/compute.py +++ b/compute.py @@ -1,9 +1,13 @@ # Matrixfunktionen für das Projekt matrixmania -from typing import List, Sequence import math +from collections.abc import Sequence + +from tabulate import tabulate -def matmul(a: Sequence[Sequence[float]], b: Sequence[Sequence[float]]) -> List[List[float]]: +def matmul( + a: Sequence[Sequence[float]], b: Sequence[Sequence[float]] +) -> list[list[float]]: """ Multiply two matrices. @@ -51,7 +55,7 @@ def matmul(a: Sequence[Sequence[float]], b: Sequence[Sequence[float]]) -> List[L ) # ---- Compute product ---- - result: List[List[float]] = [ + result: list[list[float]] = [ [0.0 for _ in range(n_cols_b)] for _ in range(n_rows_a) ] @@ -65,7 +69,7 @@ def matmul(a: Sequence[Sequence[float]], b: Sequence[Sequence[float]]) -> List[L return result -def transpose(matrix: Sequence[Sequence[float]]) -> List[List[float]]: +def transpose(matrix: Sequence[Sequence[float]]) -> list[list[float]]: """ Return the transpose of a matrix. @@ -88,7 +92,7 @@ def transpose(matrix: Sequence[Sequence[float]]) -> List[List[float]]: return [[matrix[i][j] for i in range(n_rows)] for j in range(n_cols)] -def rotate(matrix: Sequence[Sequence[float]]) -> List[List[float]]: +def rotate(matrix: Sequence[Sequence[float]]) -> list[list[float]]: """ Rotate the matrix 90 degrees clockwise. @@ -101,7 +105,6 @@ def rotate(matrix: Sequence[Sequence[float]]) -> List[List[float]]: raise ValueError("Argument must be a non-empty matrix.") if not all(isinstance(row, Sequence) for row in matrix): raise ValueError("Argument must be a sequence of sequences.") - n_rows = len(matrix) n_cols = len(matrix[0]) if n_cols == 0: raise ValueError("Matrix rows cannot be empty.") @@ -112,7 +115,7 @@ def rotate(matrix: Sequence[Sequence[float]]) -> List[List[float]]: return [list(reversed(row)) for row in transposed] -def rot_2D(theta_degrees: float) -> List[List[float]]: +def rot_2D(theta_degrees: float) -> list[list[float]]: """ Return a 2x2 rotation matrix for the given angle in degrees. @@ -127,7 +130,7 @@ def rot_2D(theta_degrees: float) -> List[List[float]]: """ if not isinstance(theta_degrees, (int, float)): - raise ValueError("Angle must be a number.") + raise TypeError("Angle must be a number.") theta = math.radians(theta_degrees) cos_theta = math.cos(theta) sin_theta = math.sin(theta) @@ -167,3 +170,5 @@ print(rot_2D(90)) print("\nrot_2D test 2") print(rot_2D(45)) +print("\nRotationsmatrix als Tabelle:") +print(tabulate(rot_2D(1.0))) diff --git a/pyproject.toml b/pyproject.toml index 7a6417e..3a776b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,4 @@ [project] name = "matrixmania" version = "0.1.0" +dependencies = ["tabulate", "ruff"] \ No newline at end of file