Requirements hinzugefügt und Code mit Ruff überprüft

This commit is contained in:
ibraevala93651 committed 2026-10-28 21:54:28 +01:00
1 parent ca4b8e3f99
commit 4272fa33c8
2 files changed
+14 -8

No files matched your search

+13 -8
View File
@@ -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)))
+1
View File
@@ -1,3 +1,4 @@
[project]
name = "matrixmania"
version = "0.1.0"
dependencies = ["tabulate", "ruff"]