The Start of Matrix Mania
This commit is contained in:
commit
e6f4cb3b88
11 files changed
+167
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
.venv/
|
||||||
|
__pycache__/
|
||||||
|
.env
|
||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
Generated
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.14 (MatrixMania)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="PyPep8Inspection" enabled="true" level="INFORMATION" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="W292" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.14 (MatrixMania)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.14 (MatrixMania)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/MatrixMania.iml" filepath="$PROJECT_DIR$/.idea/MatrixMania.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Regeln für dieses Projekt
|
||||||
|
- Code nach PEP 8, Zeilenlänge maximal 88 Zeichen.
|
||||||
|
- Jede Funktion und Methode hat einen Docstring und Type Hints.
|
||||||
|
- Vor jedem Commit: `ruff check` und `ruff format`.
|
||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
|
def matmul(matrix_a:list[list[float]], matrix_b: list[list[float]]) -> list[list[float]]:
|
||||||
|
"""
|
||||||
|
Add two numbers together.
|
||||||
|
:param matrix_a: The first Matrix
|
||||||
|
:type matrix_a: list[list[float]]
|
||||||
|
:param matrix_b: The second Matrix
|
||||||
|
:type matrix_b: list[list[float]]
|
||||||
|
:return: The Matrix Multiplication of matrix_a and matrix_b
|
||||||
|
:rtype: list[list[float]]
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if len(matrix_a[0]) != len(matrix_b):
|
||||||
|
raise ValueError("Differing Matrix Size")
|
||||||
|
target_height = len(matrix_a)
|
||||||
|
target_width = len(matrix_b[0])
|
||||||
|
|
||||||
|
end_matrix : list[list[float]]= []
|
||||||
|
|
||||||
|
|
||||||
|
for height in range(target_height):
|
||||||
|
end_matrix.append([])
|
||||||
|
for width in range(target_width):
|
||||||
|
row = matrix_a[height]
|
||||||
|
column_ = []
|
||||||
|
for b in matrix_b:
|
||||||
|
column_.append(b[width])
|
||||||
|
result_quarter = 0
|
||||||
|
for i in range(len(row)):
|
||||||
|
result_quarter += row[i] * column_[i]
|
||||||
|
end_matrix[height].append(float(result_quarter))
|
||||||
|
|
||||||
|
return end_matrix
|
||||||
|
except ValueError:
|
||||||
|
print("An Error has occurred")
|
||||||
|
except IndexError:
|
||||||
|
print("Tried to call non-existing Index")
|
||||||
|
except TypeError:
|
||||||
|
print("Tried to insert not a Number")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def transpose(matrix:list[list[float]]) -> list[list[float]]:
|
||||||
|
"""
|
||||||
|
Transposes a matrix.
|
||||||
|
:param matrix: The Matrix, that will be transposed
|
||||||
|
:type matrix: list[list[float]]
|
||||||
|
:return: The transposed matrix
|
||||||
|
:rtype: list[list[float]]
|
||||||
|
"""
|
||||||
|
|
||||||
|
transposed_matrix = []
|
||||||
|
for x in range(len(matrix[0])):
|
||||||
|
column = []
|
||||||
|
for b in matrix:
|
||||||
|
column.append(b[x])
|
||||||
|
transposed_matrix.append(column)
|
||||||
|
|
||||||
|
return transposed_matrix
|
||||||
|
|
||||||
|
def rot_2d(angle:float) -> list[list[float]]:
|
||||||
|
"""
|
||||||
|
Creates a Rotation Matrix out of the given angle
|
||||||
|
:param angle: The rotation in radians
|
||||||
|
:type angle: float
|
||||||
|
:return: The Rotation Matrix
|
||||||
|
:rtype: list[list[float]]
|
||||||
|
"""
|
||||||
|
sin = round(math.sin(angle), 4)
|
||||||
|
cos = round(math.cos(angle), 4)
|
||||||
|
return [[cos, -sin],
|
||||||
|
[sin, cos]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def print_matrix(matrix:list[list[float]]) -> None:
|
||||||
|
for row in matrix:
|
||||||
|
print(row)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
matrix_bsp_a = [[1, 2, 3], [4, 5, 6]]
|
||||||
|
matrix_bsp_b = [[1, 2], [3, 4], [5, 6]]
|
||||||
|
matrix_bsp_c = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
||||||
|
matrix_bsp_d = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
|
||||||
|
|
||||||
|
if False:
|
||||||
|
matrix_bsp_result = matmul(matrix_bsp_c, matrix_bsp_d)
|
||||||
|
print_matrix(matrix_bsp_result)
|
||||||
|
|
||||||
|
if False:
|
||||||
|
matrix_bsp_result = transpose(matrix_bsp_d)
|
||||||
|
#print_matrix(matrix_bsp_c)
|
||||||
|
print_matrix(matrix_bsp_result)
|
||||||
|
|
||||||
|
if True:
|
||||||
|
print_matrix(rot_2d(math.pi*.25))
|
||||||
|
|
||||||
|
print("Done")
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[project]
|
||||||
|
name = "matrixmania"
|
||||||
|
version = "0.1.0"
|
||||||
Reference in new issue
Block a user