From 547d90e8f7456c2f0ec402ddd0cd68b6246b7821 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 13 Mar 2026 23:25:28 +0300 Subject: [PATCH 1/9] =?UTF-8?q?"=D0=9112-513=20=D0=98=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B3=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=B1=D0=B5=D1=80?= =?UTF-8?q?=D1=82"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solutions/sem02/lesson03/task1.py | 16 +++++++++-- solutions/sem02/lesson03/task2.py | 25 ++++++++++++++-- solutions/sem02/lesson03/task3.py | 10 ++++++- solutions/sem02/lesson04/task1.py | 48 ++++++++++++++++++++++++++++--- solutions/sem02/lesson04/task2.py | 19 ++++++++++-- 5 files changed, 105 insertions(+), 13 deletions(-) diff --git a/solutions/sem02/lesson03/task1.py b/solutions/sem02/lesson03/task1.py index 2c3fc0b58..058cc9725 100644 --- a/solutions/sem02/lesson03/task1.py +++ b/solutions/sem02/lesson03/task1.py @@ -8,13 +8,23 @@ class ShapeMismatchError(Exception): def sum_arrays_vectorized( lhs: np.ndarray, rhs: np.ndarray, -) -> np.ndarray: ... +) -> np.ndarray: + if lhs.shape != rhs.shape: + raise ShapeMismatchError + return np.add(lhs, rhs) -def compute_poly_vectorized(abscissa: np.ndarray) -> np.ndarray: ... +def compute_poly_vectorized(abscissa: np.ndarray) -> np.ndarray: + return 3 * (abscissa**2) + 2 * abscissa + 1 def get_mutual_l2_distances_vectorized( lhs: np.ndarray, rhs: np.ndarray, -) -> np.ndarray: ... +) -> np.ndarray: + if lhs.shape[1] != rhs.shape[1]: + raise ShapeMismatchError + new_lhs = lhs[:, np.newaxis, :] + new_rhs = rhs[np.newaxis, :] + difference = new_lhs - new_rhs + return np.sqrt(np.sum(difference**2, axis=2)) diff --git a/solutions/sem02/lesson03/task2.py b/solutions/sem02/lesson03/task2.py index fc823c1d6..06d9059cd 100644 --- a/solutions/sem02/lesson03/task2.py +++ b/solutions/sem02/lesson03/task2.py @@ -1,4 +1,5 @@ import numpy as np +from numpy.ma.core import arccos, arctan2 class ShapeMismatchError(Exception): @@ -9,11 +10,31 @@ def convert_from_sphere( distances: np.ndarray, azimuth: np.ndarray, inclination: np.ndarray, -) -> tuple[np.ndarray, np.ndarray, np.ndarray]: ... +) -> tuple[np.ndarray, np.ndarray, np.ndarray]: + if ( + (distances.shape != azimuth.shape) + or (distances.shape != inclination.shape) + or (azimuth.shape != inclination.shape) + ): + raise ShapeMismatchError + abscissa = distances * np.sin(inclination) * np.cos(azimuth) + ordinates = distances * np.sin(inclination) * np.sin(azimuth) + applicates = distances * np.cos(inclination) + return abscissa, ordinates, applicates def convert_to_sphere( abscissa: np.ndarray, ordinates: np.ndarray, applicates: np.ndarray, -) -> tuple[np.ndarray, np.ndarray, np.ndarray]: ... +) -> tuple[np.ndarray, np.ndarray, np.ndarray]: + if ( + (abscissa.shape != ordinates.shape) + or (abscissa.shape != applicates.shape) + or (ordinates.shape != applicates.shape) + ): + raise ShapeMismatchError + distances = (abscissa**2 + ordinates**2 + applicates**2) ** 0.5 + inclication = arccos(applicates / distances) + azimuth = arctan2(ordinates, abscissa) + return distances, azimuth, inclication diff --git a/solutions/sem02/lesson03/task3.py b/solutions/sem02/lesson03/task3.py index 477acd0ce..a5246efe4 100644 --- a/solutions/sem02/lesson03/task3.py +++ b/solutions/sem02/lesson03/task3.py @@ -3,4 +3,12 @@ def get_extremum_indices( ordinates: np.ndarray, -) -> tuple[np.ndarray, np.ndarray]: ... +) -> tuple[np.ndarray, np.ndarray]: + if len(ordinates) < 3: + raise ValueError + mask_for_maximums = (ordinates[1:-1] > ordinates[:-2]) & (ordinates[1:-1] > ordinates[2:]) + mask_for_minimums = (ordinates[1:-1] < ordinates[:-2]) & (ordinates[1:-1] < ordinates[2:]) + + index_of_minimum = np.arange(1, len(ordinates) - 1)[mask_for_minimums] + index_of_maximum = np.arange(1, len(ordinates) - 1)[mask_for_maximums] + return index_of_minimum, index_of_maximum diff --git a/solutions/sem02/lesson04/task1.py b/solutions/sem02/lesson04/task1.py index 1b5526c1f..3820ed68b 100644 --- a/solutions/sem02/lesson04/task1.py +++ b/solutions/sem02/lesson04/task1.py @@ -2,16 +2,56 @@ def pad_image(image: np.ndarray, pad_size: int) -> np.ndarray: - # ваш код - return image + if pad_size < 1: + raise ValueError + if image.ndim == 2: + rows_count, columns_count = image.shape + new_image = np.zeros( + (rows_count + 2 * pad_size, columns_count + 2 * pad_size), dtype=image.dtype + ) + new_image[pad_size : pad_size + rows_count, pad_size : pad_size + columns_count] = image + else: + rows_count, columns_count, layer_count = image.shape + new_image = np.zeros( + (rows_count + 2 * pad_size, columns_count + 2 * pad_size, layer_count), + dtype=image.dtype, + ) + new_image[pad_size : pad_size + rows_count, pad_size : pad_size + columns_count, :] = image + return new_image def blur_image( image: np.ndarray, kernel_size: int, ) -> np.ndarray: - # ваш код - return image + if kernel_size % 2 == 0 or kernel_size < 1: + raise ValueError + if kernel_size == 1: + return image + + pad_size = int((kernel_size - 1) / 2) + kernel_area = kernel_size**2 + if image.ndim == 2: + rows_count, column_count = image.shape + new_image = pad_image(image, pad_size) + result = np.zeros((rows_count, column_count), dtype=image.dtype) + + for i in range(rows_count): + for j in range(column_count): + window = new_image[i : i + kernel_size, j : j + kernel_size] + result[i, j] = np.sum(window, dtype=np.int32) // kernel_area + return result + + else: + rows_count, column_count, layer_count = image.shape + new_image = pad_image(image, pad_size) + result = np.zeros((rows_count, column_count, layer_count), dtype=image.dtype) + + for i in range(rows_count): + for j in range(column_count): + window = new_image[i : i + kernel_size, j : j + kernel_size, :] + result[i, j, :] = np.sum(window, axis=(0, 1), dtype=np.int32) // kernel_area + return result if __name__ == "__main__": diff --git a/solutions/sem02/lesson04/task2.py b/solutions/sem02/lesson04/task2.py index be9a2288f..23f498072 100644 --- a/solutions/sem02/lesson04/task2.py +++ b/solutions/sem02/lesson04/task2.py @@ -2,9 +2,22 @@ def get_dominant_color_info( - image: np.ndarray[np.uint8], + image: np.ndarray, threshold: int = 5, ) -> tuple[np.uint8, float]: - # ваш код + if threshold < 1: + raise ValueError("threshold must be positive") + pixels = image.flatten() + total_pixels = len(pixels) + unique_colors = np.unique(pixels) - return 0, 0 + max_count = 0 + best_color = None + for color in unique_colors: + count = np.sum(np.abs(pixels.astype(int) - int(color)) < threshold) + if count > max_count: + max_count = count + best_color = color + + percentage = (max_count / total_pixels) * 100 + return np.uint8(best_color), percentage From ce3a8a9b11c78807082c98a87033eb52a3273593 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 13 Mar 2026 23:35:13 +0300 Subject: [PATCH 2/9] =?UTF-8?q?"=D0=98=D0=B1=D1=80=D0=B0=D0=B3=D0=B8=D0=BC?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=B1=D0=B5=D1=80=D1=82=20=D0=9112-?= =?UTF-8?q?513=20fixes"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homeworks/sem01/hw1/backoff.py | 2 -- solutions/sem01/lesson02/task3.py | 2 +- solutions/sem01/lesson08/task1.py | 1 + solutions/sem01/lesson12/task3.py | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/homeworks/sem01/hw1/backoff.py b/homeworks/sem01/hw1/backoff.py index 696ffa73a..a3373a982 100644 --- a/homeworks/sem01/hw1/backoff.py +++ b/homeworks/sem01/hw1/backoff.py @@ -1,5 +1,3 @@ -from random import uniform -from time import sleep from typing import ( Callable, ParamSpec, diff --git a/solutions/sem01/lesson02/task3.py b/solutions/sem01/lesson02/task3.py index ee2a84ecf..e997f8054 100644 --- a/solutions/sem01/lesson02/task3.py +++ b/solutions/sem01/lesson02/task3.py @@ -1,4 +1,4 @@ def get_amount_of_ways_to_climb(stair_amount: int) -> int: - step_prev, step_curr = 1, 1 + _step_prev, step_curr = 1, 1 # ваш код return step_curr diff --git a/solutions/sem01/lesson08/task1.py b/solutions/sem01/lesson08/task1.py index 4390f6c84..d4cfb0545 100644 --- a/solutions/sem01/lesson08/task1.py +++ b/solutions/sem01/lesson08/task1.py @@ -1,5 +1,6 @@ from typing import Callable + def make_averager(accumulation_period: int) -> Callable[[float], float]: # ваш код pass \ No newline at end of file diff --git a/solutions/sem01/lesson12/task3.py b/solutions/sem01/lesson12/task3.py index 64c112ccc..92ab0a860 100644 --- a/solutions/sem01/lesson12/task3.py +++ b/solutions/sem01/lesson12/task3.py @@ -1,4 +1,3 @@ -import sys class FileOut: From 66fbc34c82a0e954e80018b16e906a7e90f9f128 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 13 Mar 2026 23:38:46 +0300 Subject: [PATCH 3/9] =?UTF-8?q?"=D0=9112-513=20=D0=98=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B3=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=B1=D0=B5=D1=80?= =?UTF-8?q?=D1=82=20fixes"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solutions/sem01/lesson03/task1.py | 2 +- solutions/sem01/lesson03/task2.py | 2 +- solutions/sem01/lesson04/task1.py | 2 +- solutions/sem01/lesson04/task2.py | 2 +- solutions/sem01/lesson04/task4.py | 2 +- solutions/sem01/lesson04/task5.py | 2 +- solutions/sem01/lesson04/task6.py | 4 ++-- solutions/sem01/lesson05/task1.py | 2 +- solutions/sem01/lesson05/task2.py | 2 +- solutions/sem01/lesson05/task4.py | 2 +- solutions/sem01/lesson05/task5.py | 4 ++-- solutions/sem01/lesson05/task6.py | 2 +- solutions/sem01/lesson06/task1.py | 2 +- solutions/sem01/lesson06/task2.py | 2 +- solutions/sem01/lesson06/task3.py | 1 - solutions/sem01/lesson06/task4.py | 2 +- solutions/sem01/lesson08/task1.py | 2 +- solutions/sem01/lesson08/task2.py | 8 +++----- solutions/sem01/lesson12/task3.py | 2 -- 19 files changed, 21 insertions(+), 26 deletions(-) diff --git a/solutions/sem01/lesson03/task1.py b/solutions/sem01/lesson03/task1.py index f1d8fe26b..7b048e654 100644 --- a/solutions/sem01/lesson03/task1.py +++ b/solutions/sem01/lesson03/task1.py @@ -1,3 +1,3 @@ def flip_bits_in_range(num: int, left_bit: int, right_bit: int) -> int: # ваш код - return num \ No newline at end of file + return num diff --git a/solutions/sem01/lesson03/task2.py b/solutions/sem01/lesson03/task2.py index a3a738c2a..5cf2b6316 100644 --- a/solutions/sem01/lesson03/task2.py +++ b/solutions/sem01/lesson03/task2.py @@ -1,3 +1,3 @@ def get_cube_root(n: float, eps: float) -> float: # ваш код - return n \ No newline at end of file + return n diff --git a/solutions/sem01/lesson04/task1.py b/solutions/sem01/lesson04/task1.py index 47384423a..0135e399b 100644 --- a/solutions/sem01/lesson04/task1.py +++ b/solutions/sem01/lesson04/task1.py @@ -1,3 +1,3 @@ def is_arithmetic_progression(lst: list[list[int]]) -> bool: # ваш код - return False \ No newline at end of file + return False diff --git a/solutions/sem01/lesson04/task2.py b/solutions/sem01/lesson04/task2.py index 4591d0a3e..5d6f8ee8a 100644 --- a/solutions/sem01/lesson04/task2.py +++ b/solutions/sem01/lesson04/task2.py @@ -1,3 +1,3 @@ def merge_intervals(intervals: list[list[int, int]]) -> list[list[int, int]]: # ваш код - return [[0,0]] \ No newline at end of file + return [[0, 0]] diff --git a/solutions/sem01/lesson04/task4.py b/solutions/sem01/lesson04/task4.py index b21bc5a39..2664384d8 100644 --- a/solutions/sem01/lesson04/task4.py +++ b/solutions/sem01/lesson04/task4.py @@ -1,3 +1,3 @@ def move_zeros_to_end(nums: list[int]) -> list[int]: # ваш код - return 0 \ No newline at end of file + return 0 diff --git a/solutions/sem01/lesson04/task5.py b/solutions/sem01/lesson04/task5.py index 02d7742bb..ec6932ee4 100644 --- a/solutions/sem01/lesson04/task5.py +++ b/solutions/sem01/lesson04/task5.py @@ -1,3 +1,3 @@ def find_row_with_most_ones(matrix: list[list[int]]) -> int: # ваш код - return 0 \ No newline at end of file + return 0 diff --git a/solutions/sem01/lesson04/task6.py b/solutions/sem01/lesson04/task6.py index 16df27ca6..d16e77dda 100644 --- a/solutions/sem01/lesson04/task6.py +++ b/solutions/sem01/lesson04/task6.py @@ -1,3 +1,3 @@ -def count_cycles(arr: list[int]) -> int: +def count_cycles(arr: list[int]) -> int: # ваш код - return 0 \ No newline at end of file + return 0 diff --git a/solutions/sem01/lesson05/task1.py b/solutions/sem01/lesson05/task1.py index 9a17211e5..fdf3b5488 100644 --- a/solutions/sem01/lesson05/task1.py +++ b/solutions/sem01/lesson05/task1.py @@ -1,3 +1,3 @@ def is_palindrome(text: str) -> bool: # ваш код - return False \ No newline at end of file + return False diff --git a/solutions/sem01/lesson05/task2.py b/solutions/sem01/lesson05/task2.py index 367503802..c70b40298 100644 --- a/solutions/sem01/lesson05/task2.py +++ b/solutions/sem01/lesson05/task2.py @@ -1,3 +1,3 @@ def are_anagrams(word1: str, word2: str) -> bool: # ваш код - return False \ No newline at end of file + return False diff --git a/solutions/sem01/lesson05/task4.py b/solutions/sem01/lesson05/task4.py index 4c4e9086e..7c2c26f17 100644 --- a/solutions/sem01/lesson05/task4.py +++ b/solutions/sem01/lesson05/task4.py @@ -1,3 +1,3 @@ def unzip(compress_text: str) -> str: # ваш код - return compress_text \ No newline at end of file + return compress_text diff --git a/solutions/sem01/lesson05/task5.py b/solutions/sem01/lesson05/task5.py index 076c5bb6c..da9e6d08c 100644 --- a/solutions/sem01/lesson05/task5.py +++ b/solutions/sem01/lesson05/task5.py @@ -1,3 +1,3 @@ -def reg_validator(reg_expr: str, text: str) -> bool: +def reg_validator(reg_expr: str, text: str) -> bool: # ваш код - return False \ No newline at end of file + return False diff --git a/solutions/sem01/lesson05/task6.py b/solutions/sem01/lesson05/task6.py index 1b914ada7..63207797d 100644 --- a/solutions/sem01/lesson05/task6.py +++ b/solutions/sem01/lesson05/task6.py @@ -1,3 +1,3 @@ def simplify_path(path: str) -> str: # ваш код - return path \ No newline at end of file + return path diff --git a/solutions/sem01/lesson06/task1.py b/solutions/sem01/lesson06/task1.py index 2d1e30e96..353cb3616 100644 --- a/solutions/sem01/lesson06/task1.py +++ b/solutions/sem01/lesson06/task1.py @@ -1,3 +1,3 @@ def int_to_roman(num: int) -> str: # ваш код - return "" \ No newline at end of file + return "" diff --git a/solutions/sem01/lesson06/task2.py b/solutions/sem01/lesson06/task2.py index f535b5a0c..f1034e24e 100644 --- a/solutions/sem01/lesson06/task2.py +++ b/solutions/sem01/lesson06/task2.py @@ -1,3 +1,3 @@ def get_len_of_longest_substring(text: str) -> int: # ваш код - return 0 \ No newline at end of file + return 0 diff --git a/solutions/sem01/lesson06/task3.py b/solutions/sem01/lesson06/task3.py index 7449a1e72..b160d615a 100644 --- a/solutions/sem01/lesson06/task3.py +++ b/solutions/sem01/lesson06/task3.py @@ -2,6 +2,5 @@ def is_there_any_good_subarray( nums: list[int], k: int, ) -> bool: - # ваш код return False diff --git a/solutions/sem01/lesson06/task4.py b/solutions/sem01/lesson06/task4.py index 5b75a110c..95a7098e4 100644 --- a/solutions/sem01/lesson06/task4.py +++ b/solutions/sem01/lesson06/task4.py @@ -1,3 +1,3 @@ def count_unique_words(text: str) -> int: # ваш код - return 0 \ No newline at end of file + return 0 diff --git a/solutions/sem01/lesson08/task1.py b/solutions/sem01/lesson08/task1.py index d4cfb0545..7fa724ef8 100644 --- a/solutions/sem01/lesson08/task1.py +++ b/solutions/sem01/lesson08/task1.py @@ -3,4 +3,4 @@ def make_averager(accumulation_period: int) -> Callable[[float], float]: # ваш код - pass \ No newline at end of file + pass diff --git a/solutions/sem01/lesson08/task2.py b/solutions/sem01/lesson08/task2.py index 6e4af8707..cc2ae4303 100644 --- a/solutions/sem01/lesson08/task2.py +++ b/solutions/sem01/lesson08/task2.py @@ -2,9 +2,7 @@ T = TypeVar("T") -def collect_statistic( - statistics: dict[str, list[float, int]] -) -> Callable[[T], T]: - + +def collect_statistic(statistics: dict[str, list[float, int]]) -> Callable[[T], T]: # ваш код - pass \ No newline at end of file + pass diff --git a/solutions/sem01/lesson12/task3.py b/solutions/sem01/lesson12/task3.py index 92ab0a860..58b0986e1 100644 --- a/solutions/sem01/lesson12/task3.py +++ b/solutions/sem01/lesson12/task3.py @@ -1,5 +1,3 @@ - - class FileOut: def __init__( self, From 2b1d4f901933b694dde83492d2724f2441f10e30 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 16 Mar 2026 23:03:05 +0300 Subject: [PATCH 4/9] =?UTF-8?q?"=D0=9112-513=20=D0=98=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B3=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=B1=D0=B5=D1=80?= =?UTF-8?q?=D1=82=20lesson05"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solutions/sem02/lesson05/task1.py | 6 +++++- solutions/sem02/lesson05/task2.py | 13 ++++++++++++- solutions/sem02/lesson05/task3.py | 8 +++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/solutions/sem02/lesson05/task1.py b/solutions/sem02/lesson05/task1.py index e9c7c3c56..db09ebbe3 100644 --- a/solutions/sem02/lesson05/task1.py +++ b/solutions/sem02/lesson05/task1.py @@ -9,4 +9,8 @@ def can_satisfy_demand( costs: np.ndarray, resource_amounts: np.ndarray, demand_expected: np.ndarray, -) -> bool: ... +) -> bool: + rows_count, column_count = costs.shape + if rows_count != resource_amounts.shape[0] or column_count != demand_expected.shape[0]: + raise ShapeMismatchError + return np.all(costs @ demand_expected <= resource_amounts) diff --git a/solutions/sem02/lesson05/task2.py b/solutions/sem02/lesson05/task2.py index be1fb9d2b..4ce5725a2 100644 --- a/solutions/sem02/lesson05/task2.py +++ b/solutions/sem02/lesson05/task2.py @@ -8,4 +8,15 @@ class ShapeMismatchError(Exception): def get_projections_components( matrix: np.ndarray, vector: np.ndarray, -) -> tuple[np.ndarray | None, np.ndarray | None]: ... +) -> tuple[np.ndarray | None, np.ndarray | None]: + rows_count, column_count = matrix.shape + if rows_count != column_count or column_count != vector.shape[0]: + raise ShapeMismatchError + if np.linalg.det(matrix) == 0: + return None, None + projection_coefficient = (np.sum((matrix * vector), axis=1) / np.sum((matrix**2), axis=1))[ + :, np.newaxis + ] + proj = projection_coefficient * matrix + orth = vector - proj + return proj, orth diff --git a/solutions/sem02/lesson05/task3.py b/solutions/sem02/lesson05/task3.py index 0c66906cb..e3c3db5de 100644 --- a/solutions/sem02/lesson05/task3.py +++ b/solutions/sem02/lesson05/task3.py @@ -9,4 +9,10 @@ def adaptive_filter( Vs: np.ndarray, Vj: np.ndarray, diag_A: np.ndarray, -) -> np.ndarray: ... +) -> np.ndarray: + if Vs.shape[0] != Vj.shape[0] or Vj.shape[1] != diag_A.shape[0]: + raise ShapeMismatchError + Vjh = np.conj(Vj).transpose() + A = np.diag(diag_A) + almost_R_inv = np.linalg.inv(np.eye(Vj.shape[1]) + Vjh @ Vj @ A) + return Vs - Vj @ (almost_R_inv @ (Vjh @ Vs)) From 261cd6a80d11c007506f9d75673e4325d02b46c9 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 10 Apr 2026 16:31:18 +0300 Subject: [PATCH 5/9] =?UTF-8?q?=D0=9112-513=20=D0=98=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B3=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=B1=D0=B5=D1=80?= =?UTF-8?q?=D1=82=20lesson07?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solutions/sem02/lesson07/task1.py | 77 +++++++++++++++++++++++++++++-- solutions/sem02/lesson07/task2.py | 43 ++++++++++++++++- 2 files changed, 116 insertions(+), 4 deletions(-) diff --git a/solutions/sem02/lesson07/task1.py b/solutions/sem02/lesson07/task1.py index 3a505d89b..36301a1ad 100644 --- a/solutions/sem02/lesson07/task1.py +++ b/solutions/sem02/lesson07/task1.py @@ -13,8 +13,79 @@ def visualize_diagrams( ordinates: np.ndarray, diagram_type: Any, ) -> None: - # ваш код - pass + if abscissa.shape != ordinates.shape: + raise ShapeMismatchError + if diagram_type not in ["hist", "violin", "box"]: + raise ValueError + plt.style.use("seaborn-v0_8-darkgrid") + figure = plt.figure(figsize=(10, 10)) + grid = plt.GridSpec(4, 4, wspace=space, hspace=space) + axis_scatter = figure.add_subplot(grid[:-1, 1:]) + axis_vert = figure.add_subplot( + grid[:-1, 0], + sharey=axis_scatter, + ) + axis_hor = figure.add_subplot( + grid[-1, 1:], + sharex=axis_scatter, + ) + axis_scatter.scatter(abscissa, ordinates, color="green", alpha=0.5) + + if diagram_type == "hist": + axis_hor.hist( + abscissa, + bins=50, + color="green", + density=True, + alpha=0.5, + ) + axis_vert.hist( + ordinates, + bins=50, + color="green", + orientation="horizontal", + density=True, + alpha=0.5, + ) + + axis_hor.invert_yaxis() + axis_vert.invert_xaxis() + + if diagram_type == "violin": + axis_hor.violinplot( + abscissa, + vert=False, + showmedians=True, + ) + + axis_vert.violinplot( + ordinates, + vert=True, + showmedians=True, + ) + axis_hor.invert_yaxis() + axis_vert.invert_xaxis() + + if diagram_type == "box": + axis_hor.boxplot( + abscissa, + vert=False, + patch_artist=True, + boxprops=dict(facecolor="green"), + medianprops=dict(color="k"), + ) + + axis_vert.boxplot( + abscissa, + vert=True, + patch_artist=True, + boxprops=dict(facecolor="green"), + medianprops=dict(color="k"), + ) + axis_hor.invert_yaxis() + axis_vert.invert_xaxis() + + plt.show() if __name__ == "__main__": @@ -24,5 +95,5 @@ def visualize_diagrams( abscissa, ordinates = np.random.multivariate_normal(mean, cov, size=1000).T - visualize_diagrams(abscissa, ordinates, "hist") + visualize_diagrams(abscissa, ordinates, "violin") plt.show() diff --git a/solutions/sem02/lesson07/task2.py b/solutions/sem02/lesson07/task2.py index decd607ef..8862787b0 100644 --- a/solutions/sem02/lesson07/task2.py +++ b/solutions/sem02/lesson07/task2.py @@ -1 +1,42 @@ -# ваш код (используйте функции или классы для решения данной задачи) +import json +import numpy as np +import matplotlib.pyplot as plt + +with open("data/medic_data.json", "r", encoding="utf-8") as file: + data = json.load(file) +before = data["before"] +after = data["after"] + +shift = 0.4 +plt.style.use("dark_background") +figure, axis = plt.subplots(figsize=(9, 9)) +labels_before, counts_before = np.unique(before, return_counts=True) +labels_after, counts_after = np.unique(after, return_counts=True) +axis.set_title("Mitral disease stages", fontsize=28, fontweight="bold", c="dimgray") +axis.set_ylabel("amount of people", fontsize=20, fontweight="bold", c="dimgray") + +axis.bar( + np.arange(counts_before.size), + counts_before, + width=shift, + color="cornflowerblue", + edgecolor="blue", +) + +axis.bar( + np.arange(counts_after.size) + shift, + counts_after, + width=shift, + color="red", + edgecolor="black", +) + +axis.set_xticks( + (np.arange(labels_before.size) + np.arange(labels_after.size) + shift) / 2, + labels=labels_after, + weight="bold", +) + +axis.tick_params(axis="x", labelsize=20, labelcolor="dimgray") + +plt.show() From be3d2b81aefbf1c792a91f2054b115e944791908 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 10 Apr 2026 16:35:31 +0300 Subject: [PATCH 6/9] =?UTF-8?q?=D0=9112-513=20=D0=98=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B3=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=B1=D0=B5=D1=80?= =?UTF-8?q?=D1=82=20lesson07=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solutions/sem02/lesson07/task2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/solutions/sem02/lesson07/task2.py b/solutions/sem02/lesson07/task2.py index 8862787b0..da25afaa1 100644 --- a/solutions/sem02/lesson07/task2.py +++ b/solutions/sem02/lesson07/task2.py @@ -1,6 +1,7 @@ import json -import numpy as np + import matplotlib.pyplot as plt +import numpy as np with open("data/medic_data.json", "r", encoding="utf-8") as file: data = json.load(file) From ff0baa615d4d3dfc457f8b1c4993780cc50c4199 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 10 Apr 2026 16:48:35 +0300 Subject: [PATCH 7/9] =?UTF-8?q?=D0=9112-513=20=D0=98=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B3=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=B1=D0=B5=D1=80?= =?UTF-8?q?=D1=82=20lesson07=20fixed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solutions/sem02/lesson07/task1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/sem02/lesson07/task1.py b/solutions/sem02/lesson07/task1.py index 36301a1ad..94d2a371c 100644 --- a/solutions/sem02/lesson07/task1.py +++ b/solutions/sem02/lesson07/task1.py @@ -18,6 +18,7 @@ def visualize_diagrams( if diagram_type not in ["hist", "violin", "box"]: raise ValueError plt.style.use("seaborn-v0_8-darkgrid") + space = 0.2 figure = plt.figure(figsize=(10, 10)) grid = plt.GridSpec(4, 4, wspace=space, hspace=space) axis_scatter = figure.add_subplot(grid[:-1, 1:]) @@ -95,5 +96,4 @@ def visualize_diagrams( abscissa, ordinates = np.random.multivariate_normal(mean, cov, size=1000).T - visualize_diagrams(abscissa, ordinates, "violin") - plt.show() + visualize_diagrams(abscissa, ordinates, "hist") From 39f72edeb32c1be186a0b0cf6b674286cfd569ad Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 10 Apr 2026 16:54:21 +0300 Subject: [PATCH 8/9] =?UTF-8?q?=D0=9112-513=20=D0=98=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B3=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=B1=D0=B5=D1=80?= =?UTF-8?q?=D1=82=20lesson07=20fixed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deprecated_tests/sem02/tests/.idea/.gitignore | 5 +++++ .../inspectionProfiles/Project_Default.xml | 19 +++++++++++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++++ deprecated_tests/sem02/tests/.idea/misc.xml | 4 ++++ .../sem02/tests/.idea/modules.xml | 8 ++++++++ deprecated_tests/sem02/tests/.idea/tests.iml | 8 ++++++++ deprecated_tests/sem02/tests/.idea/vcs.xml | 6 ++++++ solutions/sem02/lesson03/.idea/.gitignore | 5 +++++ .../inspectionProfiles/Project_Default.xml | 10 ++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++++ solutions/sem02/lesson03/.idea/lesson03.iml | 8 ++++++++ solutions/sem02/lesson03/.idea/misc.xml | 7 +++++++ solutions/sem02/lesson03/.idea/modules.xml | 8 ++++++++ solutions/sem02/lesson03/.idea/vcs.xml | 6 ++++++ solutions/sem02/lesson04/.idea/.gitignore | 5 +++++ solutions/sem02/lesson04/.idea/.name | 1 + .../inspectionProfiles/Project_Default.xml | 10 ++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++++ solutions/sem02/lesson04/.idea/lesson04.iml | 10 ++++++++++ solutions/sem02/lesson04/.idea/misc.xml | 7 +++++++ solutions/sem02/lesson04/.idea/modules.xml | 8 ++++++++ solutions/sem02/lesson04/.idea/vcs.xml | 6 ++++++ solutions/sem02/lesson05/.idea/.gitignore | 5 +++++ solutions/sem02/lesson05/.idea/.name | 1 + .../inspectionProfiles/Project_Default.xml | 19 +++++++++++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++++ solutions/sem02/lesson05/.idea/lesson05.iml | 8 ++++++++ solutions/sem02/lesson05/.idea/misc.xml | 7 +++++++ solutions/sem02/lesson05/.idea/modules.xml | 8 ++++++++ solutions/sem02/lesson05/.idea/vcs.xml | 6 ++++++ solutions/sem02/lesson07/.idea/.gitignore | 5 +++++ solutions/sem02/lesson07/.idea/.name | 1 + .../inspectionProfiles/Project_Default.xml | 19 +++++++++++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++++ solutions/sem02/lesson07/.idea/lesson07.iml | 8 ++++++++ solutions/sem02/lesson07/.idea/misc.xml | 7 +++++++ solutions/sem02/lesson07/.idea/modules.xml | 8 ++++++++ solutions/sem02/lesson07/.idea/vcs.xml | 6 ++++++ solutions/sem02/lesson07/__init__.py | 0 39 files changed, 279 insertions(+) create mode 100644 deprecated_tests/sem02/tests/.idea/.gitignore create mode 100644 deprecated_tests/sem02/tests/.idea/inspectionProfiles/Project_Default.xml create mode 100644 deprecated_tests/sem02/tests/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 deprecated_tests/sem02/tests/.idea/misc.xml create mode 100644 deprecated_tests/sem02/tests/.idea/modules.xml create mode 100644 deprecated_tests/sem02/tests/.idea/tests.iml create mode 100644 deprecated_tests/sem02/tests/.idea/vcs.xml create mode 100644 solutions/sem02/lesson03/.idea/.gitignore create mode 100644 solutions/sem02/lesson03/.idea/inspectionProfiles/Project_Default.xml create mode 100644 solutions/sem02/lesson03/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 solutions/sem02/lesson03/.idea/lesson03.iml create mode 100644 solutions/sem02/lesson03/.idea/misc.xml create mode 100644 solutions/sem02/lesson03/.idea/modules.xml create mode 100644 solutions/sem02/lesson03/.idea/vcs.xml create mode 100644 solutions/sem02/lesson04/.idea/.gitignore create mode 100644 solutions/sem02/lesson04/.idea/.name create mode 100644 solutions/sem02/lesson04/.idea/inspectionProfiles/Project_Default.xml create mode 100644 solutions/sem02/lesson04/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 solutions/sem02/lesson04/.idea/lesson04.iml create mode 100644 solutions/sem02/lesson04/.idea/misc.xml create mode 100644 solutions/sem02/lesson04/.idea/modules.xml create mode 100644 solutions/sem02/lesson04/.idea/vcs.xml create mode 100644 solutions/sem02/lesson05/.idea/.gitignore create mode 100644 solutions/sem02/lesson05/.idea/.name create mode 100644 solutions/sem02/lesson05/.idea/inspectionProfiles/Project_Default.xml create mode 100644 solutions/sem02/lesson05/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 solutions/sem02/lesson05/.idea/lesson05.iml create mode 100644 solutions/sem02/lesson05/.idea/misc.xml create mode 100644 solutions/sem02/lesson05/.idea/modules.xml create mode 100644 solutions/sem02/lesson05/.idea/vcs.xml create mode 100644 solutions/sem02/lesson07/.idea/.gitignore create mode 100644 solutions/sem02/lesson07/.idea/.name create mode 100644 solutions/sem02/lesson07/.idea/inspectionProfiles/Project_Default.xml create mode 100644 solutions/sem02/lesson07/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 solutions/sem02/lesson07/.idea/lesson07.iml create mode 100644 solutions/sem02/lesson07/.idea/misc.xml create mode 100644 solutions/sem02/lesson07/.idea/modules.xml create mode 100644 solutions/sem02/lesson07/.idea/vcs.xml create mode 100644 solutions/sem02/lesson07/__init__.py diff --git a/deprecated_tests/sem02/tests/.idea/.gitignore b/deprecated_tests/sem02/tests/.idea/.gitignore new file mode 100644 index 000000000..b58b603fe --- /dev/null +++ b/deprecated_tests/sem02/tests/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/deprecated_tests/sem02/tests/.idea/inspectionProfiles/Project_Default.xml b/deprecated_tests/sem02/tests/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..04830b5ba --- /dev/null +++ b/deprecated_tests/sem02/tests/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,19 @@ + + + + \ No newline at end of file diff --git a/deprecated_tests/sem02/tests/.idea/inspectionProfiles/profiles_settings.xml b/deprecated_tests/sem02/tests/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..105ce2da2 --- /dev/null +++ b/deprecated_tests/sem02/tests/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/deprecated_tests/sem02/tests/.idea/misc.xml b/deprecated_tests/sem02/tests/.idea/misc.xml new file mode 100644 index 000000000..23231ce59 --- /dev/null +++ b/deprecated_tests/sem02/tests/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/deprecated_tests/sem02/tests/.idea/modules.xml b/deprecated_tests/sem02/tests/.idea/modules.xml new file mode 100644 index 000000000..dac5cbb11 --- /dev/null +++ b/deprecated_tests/sem02/tests/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/deprecated_tests/sem02/tests/.idea/tests.iml b/deprecated_tests/sem02/tests/.idea/tests.iml new file mode 100644 index 000000000..d8b3f6cbf --- /dev/null +++ b/deprecated_tests/sem02/tests/.idea/tests.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/deprecated_tests/sem02/tests/.idea/vcs.xml b/deprecated_tests/sem02/tests/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/deprecated_tests/sem02/tests/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson03/.idea/.gitignore b/solutions/sem02/lesson03/.idea/.gitignore new file mode 100644 index 000000000..b58b603fe --- /dev/null +++ b/solutions/sem02/lesson03/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/solutions/sem02/lesson03/.idea/inspectionProfiles/Project_Default.xml b/solutions/sem02/lesson03/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..146ab09b7 --- /dev/null +++ b/solutions/sem02/lesson03/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson03/.idea/inspectionProfiles/profiles_settings.xml b/solutions/sem02/lesson03/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..105ce2da2 --- /dev/null +++ b/solutions/sem02/lesson03/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson03/.idea/lesson03.iml b/solutions/sem02/lesson03/.idea/lesson03.iml new file mode 100644 index 000000000..d8b3f6cbf --- /dev/null +++ b/solutions/sem02/lesson03/.idea/lesson03.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson03/.idea/misc.xml b/solutions/sem02/lesson03/.idea/misc.xml new file mode 100644 index 000000000..1d3ce46ba --- /dev/null +++ b/solutions/sem02/lesson03/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson03/.idea/modules.xml b/solutions/sem02/lesson03/.idea/modules.xml new file mode 100644 index 000000000..2a359138f --- /dev/null +++ b/solutions/sem02/lesson03/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson03/.idea/vcs.xml b/solutions/sem02/lesson03/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/solutions/sem02/lesson03/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson04/.idea/.gitignore b/solutions/sem02/lesson04/.idea/.gitignore new file mode 100644 index 000000000..b58b603fe --- /dev/null +++ b/solutions/sem02/lesson04/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/solutions/sem02/lesson04/.idea/.name b/solutions/sem02/lesson04/.idea/.name new file mode 100644 index 000000000..f7361a433 --- /dev/null +++ b/solutions/sem02/lesson04/.idea/.name @@ -0,0 +1 @@ +task2.py \ No newline at end of file diff --git a/solutions/sem02/lesson04/.idea/inspectionProfiles/Project_Default.xml b/solutions/sem02/lesson04/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..146ab09b7 --- /dev/null +++ b/solutions/sem02/lesson04/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson04/.idea/inspectionProfiles/profiles_settings.xml b/solutions/sem02/lesson04/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..105ce2da2 --- /dev/null +++ b/solutions/sem02/lesson04/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson04/.idea/lesson04.iml b/solutions/sem02/lesson04/.idea/lesson04.iml new file mode 100644 index 000000000..e4bfc3d02 --- /dev/null +++ b/solutions/sem02/lesson04/.idea/lesson04.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson04/.idea/misc.xml b/solutions/sem02/lesson04/.idea/misc.xml new file mode 100644 index 000000000..0ca6009fc --- /dev/null +++ b/solutions/sem02/lesson04/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson04/.idea/modules.xml b/solutions/sem02/lesson04/.idea/modules.xml new file mode 100644 index 000000000..8b84b5071 --- /dev/null +++ b/solutions/sem02/lesson04/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson04/.idea/vcs.xml b/solutions/sem02/lesson04/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/solutions/sem02/lesson04/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson05/.idea/.gitignore b/solutions/sem02/lesson05/.idea/.gitignore new file mode 100644 index 000000000..b58b603fe --- /dev/null +++ b/solutions/sem02/lesson05/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/solutions/sem02/lesson05/.idea/.name b/solutions/sem02/lesson05/.idea/.name new file mode 100644 index 000000000..f31b987f1 --- /dev/null +++ b/solutions/sem02/lesson05/.idea/.name @@ -0,0 +1 @@ +task3.py \ No newline at end of file diff --git a/solutions/sem02/lesson05/.idea/inspectionProfiles/Project_Default.xml b/solutions/sem02/lesson05/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..04830b5ba --- /dev/null +++ b/solutions/sem02/lesson05/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,19 @@ + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson05/.idea/inspectionProfiles/profiles_settings.xml b/solutions/sem02/lesson05/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..105ce2da2 --- /dev/null +++ b/solutions/sem02/lesson05/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson05/.idea/lesson05.iml b/solutions/sem02/lesson05/.idea/lesson05.iml new file mode 100644 index 000000000..d8b3f6cbf --- /dev/null +++ b/solutions/sem02/lesson05/.idea/lesson05.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson05/.idea/misc.xml b/solutions/sem02/lesson05/.idea/misc.xml new file mode 100644 index 000000000..1d3ce46ba --- /dev/null +++ b/solutions/sem02/lesson05/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson05/.idea/modules.xml b/solutions/sem02/lesson05/.idea/modules.xml new file mode 100644 index 000000000..47a70296d --- /dev/null +++ b/solutions/sem02/lesson05/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson05/.idea/vcs.xml b/solutions/sem02/lesson05/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/solutions/sem02/lesson05/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson07/.idea/.gitignore b/solutions/sem02/lesson07/.idea/.gitignore new file mode 100644 index 000000000..b58b603fe --- /dev/null +++ b/solutions/sem02/lesson07/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/solutions/sem02/lesson07/.idea/.name b/solutions/sem02/lesson07/.idea/.name new file mode 100644 index 000000000..f7361a433 --- /dev/null +++ b/solutions/sem02/lesson07/.idea/.name @@ -0,0 +1 @@ +task2.py \ No newline at end of file diff --git a/solutions/sem02/lesson07/.idea/inspectionProfiles/Project_Default.xml b/solutions/sem02/lesson07/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..04830b5ba --- /dev/null +++ b/solutions/sem02/lesson07/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,19 @@ + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson07/.idea/inspectionProfiles/profiles_settings.xml b/solutions/sem02/lesson07/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..105ce2da2 --- /dev/null +++ b/solutions/sem02/lesson07/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson07/.idea/lesson07.iml b/solutions/sem02/lesson07/.idea/lesson07.iml new file mode 100644 index 000000000..d8b3f6cbf --- /dev/null +++ b/solutions/sem02/lesson07/.idea/lesson07.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson07/.idea/misc.xml b/solutions/sem02/lesson07/.idea/misc.xml new file mode 100644 index 000000000..1d3ce46ba --- /dev/null +++ b/solutions/sem02/lesson07/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson07/.idea/modules.xml b/solutions/sem02/lesson07/.idea/modules.xml new file mode 100644 index 000000000..2f08ad53f --- /dev/null +++ b/solutions/sem02/lesson07/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson07/.idea/vcs.xml b/solutions/sem02/lesson07/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/solutions/sem02/lesson07/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/solutions/sem02/lesson07/__init__.py b/solutions/sem02/lesson07/__init__.py new file mode 100644 index 000000000..e69de29bb From 70b1bef79413aac86e60003e0bd6b9c569247c10 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 17 Apr 2026 22:52:56 +0300 Subject: [PATCH 9/9] =?UTF-8?q?=D0=9112-513=20=D0=98=D0=B1=D0=B0=D1=80?= =?UTF-8?q?=D0=B3=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=B1=D0=B5=D1=80?= =?UTF-8?q?=D1=82=20lesson08?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solutions/sem02/lesson08/task1.py | 78 +++++++++++++++++++++++-------- solutions/sem02/lesson08/task2.py | 37 +++++++-------- 2 files changed, 75 insertions(+), 40 deletions(-) diff --git a/solutions/sem02/lesson08/task1.py b/solutions/sem02/lesson08/task1.py index 89f88572f..9cafcb101 100644 --- a/solutions/sem02/lesson08/task1.py +++ b/solutions/sem02/lesson08/task1.py @@ -1,34 +1,71 @@ from functools import partial - import matplotlib.pyplot as plt import numpy as np - -from IPython.display import HTML from matplotlib.animation import FuncAnimation def create_modulation_animation( - modulation, - fc, - num_frames, - plot_duration, - time_step=0.001, - animation_step=0.01, - save_path="" + modulation, fc, num_frames, plot_duration, time_step=0.001, animation_step=0.01, save_path="" ) -> FuncAnimation: - # ваш код - return FuncAnimation() + fig, ax = plt.subplots(figsize=(10, 6)) + + total_duration = plot_duration + num_frames * animation_step + t_full = np.arange(0, total_duration, time_step) + carrier_full = np.cos(2 * np.pi * fc * t_full) + modulating_full = modulation(t_full) + signal_full = modulating_full * carrier_full + + window_samples = int(plot_duration / time_step) + t_window = t_full[:window_samples] + signal_window = signal_full[:window_samples] + line = ax.plot(t_window, signal_window)[0] + + ax.set_xlim(0, plot_duration) + ax.set_ylim(-2, 2) + ax.set_xlabel("Время (с)") + ax.set_ylabel("Амплитуда") + ax.set_title("Анимация модулированного сигнала") + ax.grid(True) + + def update_frame(frame, t_full, signal_full, window_samples, time_step, plot_duration): + current_shift = frame * animation_step + start_idx = int(current_shift / time_step) + if start_idx + window_samples >= len(t_full): + start_idx = 0 + end_idx = start_idx + window_samples + t_current = t_full[start_idx:end_idx] + signal_current = signal_full[start_idx:end_idx] + line.set_xdata(t_current) + line.set_ydata(signal_current) + ax.set_xlim(t_current[0], t_current[-1]) + return line + + update_with_params = partial( + update_frame, + t_full=t_full, + signal_full=signal_full, + window_samples=window_samples, + time_step=time_step, + plot_duration=plot_duration, + ) + + animation = FuncAnimation( + fig=fig, func=update_with_params, frames=num_frames, interval=50, repeat=True, blit=False + ) + animation.save(save_path, writer="pillow", fps=20) + return animation if __name__ == "__main__": + def modulation_function(t): - return np.cos(t * 6) + return np.cos(t * 6) - num_frames = 100 - plot_duration = np.pi / 2 - time_step = 0.001 - animation_step = np.pi / 200 - fc = 50 + num_frames = 100 + plot_duration = np.pi / 2 + time_step = 0.001 + animation_step = np.pi / 200 + fc = 50 save_path_with_modulation = "modulated_signal.gif" animation = create_modulation_animation( @@ -38,6 +75,7 @@ def modulation_function(t): plot_duration=plot_duration, time_step=time_step, animation_step=animation_step, - save_path=save_path_with_modulation + save_path=save_path_with_modulation, ) - HTML(animation.to_jshtml()) \ No newline at end of file + + plt.show() diff --git a/solutions/sem02/lesson08/task2.py b/solutions/sem02/lesson08/task2.py index b677c0702..99902185c 100644 --- a/solutions/sem02/lesson08/task2.py +++ b/solutions/sem02/lesson08/task2.py @@ -7,28 +7,26 @@ from matplotlib.animation import FuncAnimation - - def animate_wave_algorithm( - maze: np.ndarray, - start: tuple[int, int], - end: tuple[int, int], - save_path: str = "" -) -> FuncAnimation: + maze: np.ndarray, start: tuple[int, int], end: tuple[int, int], save_path: str = "" +) -> FuncAnimation: # ваш код return FuncAnimation() + if __name__ == "__main__": # Пример 1 - maze = np.array([ - [0, 0, 0, 0, 0, 0, 0], - [0, 1, 1, 1, 1, 1, 0], - [1, 1, 0, 1, 0, 1, 0], - [0, 0, 1, 1, 0, 1, 0], - [0, 0, 0, 0, 0, 1, 0], - [1, 1, 1, 1, 1, 1, 0], - [0, 0, 0, 0, 0, 0, 0], - ]) + maze = np.array( + [ + [0, 0, 0, 0, 0, 0, 0], + [0, 1, 1, 1, 1, 1, 0], + [1, 1, 0, 1, 0, 1, 0], + [0, 0, 1, 1, 0, 1, 0], + [0, 0, 0, 0, 0, 1, 0], + [1, 1, 1, 1, 1, 1, 0], + [0, 0, 0, 0, 0, 0, 0], + ] + ) start = (2, 0) end = (5, 0) @@ -36,9 +34,9 @@ def animate_wave_algorithm( animation = animate_wave_algorithm(maze, start, end, save_path) HTML(animation.to_jshtml()) - + # Пример 2 - + maze_path = "./data/maze.npy" loaded_maze = np.load(maze_path) @@ -49,5 +47,4 @@ def animate_wave_algorithm( loaded_animation = animate_wave_algorithm(loaded_maze, start, end, loaded_save_path) HTML(loaded_animation.to_jshtml()) - - \ No newline at end of file +