Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab9 #52

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Lab9 #52

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added Haylo_KM-42.txt
Empty file.
21 changes: 21 additions & 0 deletions lab8(1).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
print("Welcome to task 1!")
import re
pose_estimation = "[BodyPart:0-(0.55, 0.17) score=0.81 BodyPart:1-(0.49, 0.27) score=0.85 BodyPart:2-(0.41, 0.26) score=0.67 BodyPart:3-(0.33, 0.37) score=0.72 BodyPart:4-(0.36, 0.48) score=0.78 BodyPart:5-(0.58, 0.27) score=0.81 BodyPart:6-(0.65, 0.38) score=0.88 BodyPart:7-(0.62, 0.48) score=0.86 BodyPart:8-(0.43, 0.48) score=0.60 BodyPart:9-(0.43, 0.66) score=0.67 BodyPart:10-(0.53, 0.79) score=0.56 BodyPart:11-(0.53, 0.48) score=0.56 BodyPart:12-(0.59, 0.66) score=0.75 BodyPart:13-(0.49, 0.80) score=0.50 BodyPart:14-(0.54, 0.15) score=0.73 BodyPart:15-(0.56, 0.15) score=0.85 BodyPart:16-(0.48, 0.16) score=0.81 BodyPart:17-(0.83, 0.18) score=0.79]"
points_pattern = r"\(([\d.]+),\s*([\d.]+)\)"
points_comp = re.compile(points_pattern)
points_match = points_comp.findall(pose_estimation)
points = []
for i in points_match:
points.extend([float(i[0]), float(i[1])])
print("Points: ", points)
score_pattern = r"score=([\d.]+)"
score_comp = re.compile(score_pattern)
score_match = score_comp.findall(pose_estimation)
score = []
for j in score_match:
score.append(float(j))
print("Score:", score)



# points_pattern = "[\d\.\(\)]+"
31 changes: 31 additions & 0 deletions lab8(2).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
print("Welcome to task 2!")
import math
while True:
try:
a = float(input("Enter coefficent a: "))
b = float(input("Enter coefficient b: "))
c = float(input("Enter coefficient c: "))

D = b **2 - 4 * a * c
if D == 0:
x = -b / (2*a)
print("The discriminant: ", D)
print("The answer 'x': ", x)
break
elif D < 0:
print("There are no roots roots!")
break
else:
x1 = (-b + math.sqrt(D)) / (2 * a)
x2 = (-b - math.sqrt(D)) / (2 * a)
print("The discriminant: ", D)
print("The first answer 'x1': ", round(x1, 4))
print("The second answer 'x2': ", round(x2, 4))
break
except ZeroDivisionError:
print("Error: Division by zero! Coefficient 'a' cannot be zero!")
break
except ValueError:
print("Error: Enter valid numbers for a,b,c")


56 changes: 56 additions & 0 deletions lab9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import numpy as np
import itertools
print("Welcome to the task!")
def random_matrix(dim):
"""
The function generates dim x dim array of integers
between 0 and 10.
"""
matrix = np.random.randint(10, size = (dim, dim))
return matrix

def permutations(size):
"""
Generates a list of all permutations of indices for a given size.
"""
return list(itertools.permutations(range(size)))

def product(matrix, permutation):
"""
Computes the product of elements in the matrix for the given permutation
considering the sign based on the number of inversions in the permutation.
"""
product = 1
sign = 1
for i in range (len(permutation)):
product *= matrix [i][permutation[i]]
for i in range (len(permutation)):
for j in range(i+1, len(permutation)):
if permutation[i] > permutation[j]:
sign *= -1
return product*sign

def determinant(matrix):
"""
Computes the determinant of the matrix using the permutation rule.
"""
size = len(matrix)
perm_list = permutations(size)
det = sum(product(matrix, perm) for perm in perm_list )
return det


try:
dim = int(input("Enter any positive number(size): "))
if dim <1:
print("Enter positive number!")
else:
matrix = random_matrix(dim)
print("Generated matrix:\n", matrix)
det = determinant(matrix)
print("Determinant is calculated according to the permutatuion rule", det)

det_np = round(np.linalg.det(matrix))
print("Determinant generated by np.linalg.det:", det_np)
except ValueError:
print("Only numbers can be entered")