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/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/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 4390f6c84..7fa724ef8 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 + 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 64c112ccc..58b0986e1 100644 --- a/solutions/sem01/lesson12/task3.py +++ b/solutions/sem01/lesson12/task3.py @@ -1,6 +1,3 @@ -import sys - - class FileOut: def __init__( self, 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/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/.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/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 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/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)) 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 diff --git a/solutions/sem02/lesson07/task1.py b/solutions/sem02/lesson07/task1.py index 3a505d89b..94d2a371c 100644 --- a/solutions/sem02/lesson07/task1.py +++ b/solutions/sem02/lesson07/task1.py @@ -13,8 +13,80 @@ 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") + 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:]) + 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__": @@ -25,4 +97,3 @@ def visualize_diagrams( abscissa, ordinates = np.random.multivariate_normal(mean, cov, size=1000).T visualize_diagrams(abscissa, ordinates, "hist") - plt.show() diff --git a/solutions/sem02/lesson07/task2.py b/solutions/sem02/lesson07/task2.py index decd607ef..da25afaa1 100644 --- a/solutions/sem02/lesson07/task2.py +++ b/solutions/sem02/lesson07/task2.py @@ -1 +1,43 @@ -# ваш код (используйте функции или классы для решения данной задачи) +import json + +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) +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() 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 + diff --git a/solutions/sem02/lesson10/task1.ipynb b/solutions/sem02/lesson10/task1.ipynb index 4b4e9e335..6974f4f9b 100644 --- a/solutions/sem02/lesson10/task1.ipynb +++ b/solutions/sem02/lesson10/task1.ipynb @@ -34,17 +34,177 @@ }, { "cell_type": "code", - "execution_count": null, "id": "d7b00711", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2026-05-01T13:50:11.045562Z", + "start_time": "2026-05-01T13:50:11.016940Z" + } + }, "source": [ "import seaborn as sns\n", - "\n", + "import numpy as np\n", + "import pandas as pd\n", "\n", "titanic_data = sns.load_dataset(\"titanic\")\n", "titanic_data.sample(5)" - ] + ], + "outputs": [ + { + "data": { + "text/plain": [ + " survived pclass sex age sibsp parch fare embarked class \\\n", + "336 0 1 male 29.0 1 0 66.6000 S First \n", + "828 1 3 male NaN 0 0 7.7500 Q Third \n", + "721 0 3 male 17.0 1 0 7.0542 S Third \n", + "98 1 2 female 34.0 0 1 23.0000 S Second \n", + "625 0 1 male 61.0 0 0 32.3208 S First \n", + "\n", + " who adult_male deck embark_town alive alone \n", + "336 man True C Southampton no False \n", + "828 man True NaN Queenstown yes True \n", + "721 man True NaN Southampton no False \n", + "98 woman False NaN Southampton yes False \n", + "625 man True D Southampton no True " + ], + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
survivedpclasssexagesibspparchfareembarkedclasswhoadult_maledeckembark_townalivealone
33601male29.01066.6000SFirstmanTrueCSouthamptonnoFalse
82813maleNaN007.7500QThirdmanTrueNaNQueenstownyesTrue
72103male17.0107.0542SThirdmanTrueNaNSouthamptonnoFalse
9812female34.00123.0000SSecondwomanFalseNaNSouthamptonyesFalse
62501male61.00032.3208SFirstmanTrueDSouthamptonnoTrue
\n", + "
" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "execution_count": 102 }, { "cell_type": "markdown", @@ -66,13 +226,42 @@ }, { "cell_type": "code", - "execution_count": null, "id": "cd2f1773", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2026-05-01T13:50:13.447518Z", + "start_time": "2026-05-01T13:50:13.441353Z" + } + }, "source": [ - "# ваш код" - ] + "nan_counts = titanic_data.isna().sum()\n", + "print(nan_counts)" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "survived 0\n", + "pclass 0\n", + "sex 0\n", + "age 177\n", + "sibsp 0\n", + "parch 0\n", + "fare 0\n", + "embarked 2\n", + "class 0\n", + "who 0\n", + "adult_male 0\n", + "deck 688\n", + "embark_town 2\n", + "alive 0\n", + "alone 0\n", + "dtype: int64\n" + ] + } + ], + "execution_count": 103 }, { "cell_type": "markdown", @@ -88,13 +277,285 @@ }, { "cell_type": "code", - "execution_count": null, "id": "7e458447", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2026-05-01T13:50:15.425055Z", + "start_time": "2026-05-01T13:50:15.395684Z" + } + }, "source": [ - "# ваш код" - ] + "titanic_data = titanic_data.dropna(thresh=int(0.5*len(titanic_data)), axis=1)\n", + "titanic_data = titanic_data.dropna(thresh=int(0.5*len(titanic_data.columns)), axis=0)\n", + "titanic_data" + ], + "outputs": [ + { + "data": { + "text/plain": [ + " survived pclass sex age sibsp parch fare embarked class \\\n", + "0 0 3 male 22.0 1 0 7.2500 S Third \n", + "1 1 1 female 38.0 1 0 71.2833 C First \n", + "2 1 3 female 26.0 0 0 7.9250 S Third \n", + "3 1 1 female 35.0 1 0 53.1000 S First \n", + "4 0 3 male 35.0 0 0 8.0500 S Third \n", + ".. ... ... ... ... ... ... ... ... ... \n", + "886 0 2 male 27.0 0 0 13.0000 S Second \n", + "887 1 1 female 19.0 0 0 30.0000 S First \n", + "888 0 3 female NaN 1 2 23.4500 S Third \n", + "889 1 1 male 26.0 0 0 30.0000 C First \n", + "890 0 3 male 32.0 0 0 7.7500 Q Third \n", + "\n", + " who adult_male embark_town alive alone \n", + "0 man True Southampton no False \n", + "1 woman False Cherbourg yes False \n", + "2 woman False Southampton yes True \n", + "3 woman False Southampton yes False \n", + "4 man True Southampton no True \n", + ".. ... ... ... ... ... \n", + "886 man True Southampton no True \n", + "887 woman False Southampton yes True \n", + "888 woman False Southampton no False \n", + "889 man True Cherbourg yes True \n", + "890 man True Queenstown no True \n", + "\n", + "[891 rows x 14 columns]" + ], + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
survivedpclasssexagesibspparchfareembarkedclasswhoadult_maleembark_townalivealone
003male22.0107.2500SThirdmanTrueSouthamptonnoFalse
111female38.01071.2833CFirstwomanFalseCherbourgyesFalse
213female26.0007.9250SThirdwomanFalseSouthamptonyesTrue
311female35.01053.1000SFirstwomanFalseSouthamptonyesFalse
403male35.0008.0500SThirdmanTrueSouthamptonnoTrue
.............................................
88602male27.00013.0000SSecondmanTrueSouthamptonnoTrue
88711female19.00030.0000SFirstwomanFalseSouthamptonyesTrue
88803femaleNaN1223.4500SThirdwomanFalseSouthamptonnoFalse
88911male26.00030.0000CFirstmanTrueCherbourgyesTrue
89003male32.0007.7500QThirdmanTrueQueenstownnoTrue
\n", + "

891 rows × 14 columns

\n", + "
" + ] + }, + "execution_count": 104, + "metadata": {}, + "output_type": "execute_result" + } + ], + "execution_count": 104 }, { "cell_type": "markdown", @@ -111,13 +572,290 @@ }, { "cell_type": "code", - "execution_count": null, "id": "f7db5e99", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2026-05-01T13:50:18.298038Z", + "start_time": "2026-05-01T13:50:18.279302Z" + } + }, "source": [ - "# ваш код" - ] + "for who in [\"man\", \"woman\", \"child\"]:\n", + " mask = (titanic_data[\"age\"].isnull()) & (titanic_data[\"who\"] == who)\n", + " median_val = titanic_data[\n", + " (titanic_data[\"age\"].notnull()) & (titanic_data[\"who\"] == who)\n", + " ][\"age\"].median()\n", + " titanic_data.loc[mask, \"age\"] = median_val.round()\n", + "\n", + "titanic_data" + ], + "outputs": [ + { + "data": { + "text/plain": [ + " survived pclass sex age sibsp parch fare embarked class \\\n", + "0 0 3 male 22.0 1 0 7.2500 S Third \n", + "1 1 1 female 38.0 1 0 71.2833 C First \n", + "2 1 3 female 26.0 0 0 7.9250 S Third \n", + "3 1 1 female 35.0 1 0 53.1000 S First \n", + "4 0 3 male 35.0 0 0 8.0500 S Third \n", + ".. ... ... ... ... ... ... ... ... ... \n", + "886 0 2 male 27.0 0 0 13.0000 S Second \n", + "887 1 1 female 19.0 0 0 30.0000 S First \n", + "888 0 3 female 30.0 1 2 23.4500 S Third \n", + "889 1 1 male 26.0 0 0 30.0000 C First \n", + "890 0 3 male 32.0 0 0 7.7500 Q Third \n", + "\n", + " who adult_male embark_town alive alone \n", + "0 man True Southampton no False \n", + "1 woman False Cherbourg yes False \n", + "2 woman False Southampton yes True \n", + "3 woman False Southampton yes False \n", + "4 man True Southampton no True \n", + ".. ... ... ... ... ... \n", + "886 man True Southampton no True \n", + "887 woman False Southampton yes True \n", + "888 woman False Southampton no False \n", + "889 man True Cherbourg yes True \n", + "890 man True Queenstown no True \n", + "\n", + "[891 rows x 14 columns]" + ], + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
survivedpclasssexagesibspparchfareembarkedclasswhoadult_maleembark_townalivealone
003male22.0107.2500SThirdmanTrueSouthamptonnoFalse
111female38.01071.2833CFirstwomanFalseCherbourgyesFalse
213female26.0007.9250SThirdwomanFalseSouthamptonyesTrue
311female35.01053.1000SFirstwomanFalseSouthamptonyesFalse
403male35.0008.0500SThirdmanTrueSouthamptonnoTrue
.............................................
88602male27.00013.0000SSecondmanTrueSouthamptonnoTrue
88711female19.00030.0000SFirstwomanFalseSouthamptonyesTrue
88803female30.01223.4500SThirdwomanFalseSouthamptonnoFalse
88911male26.00030.0000CFirstmanTrueCherbourgyesTrue
89003male32.0007.7500QThirdmanTrueQueenstownnoTrue
\n", + "

891 rows × 14 columns

\n", + "
" + ] + }, + "execution_count": 105, + "metadata": {}, + "output_type": "execute_result" + } + ], + "execution_count": 105 }, { "cell_type": "markdown", @@ -131,13 +869,16 @@ }, { "cell_type": "code", - "execution_count": null, "id": "67a0c6bc", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2026-05-01T13:50:21.390686Z", + "start_time": "2026-05-01T13:50:21.383936Z" + } + }, + "source": "titanic_data = titanic_data.dropna(thresh=len(titanic_data.columns)-1)", "outputs": [], - "source": [ - "# ваш код" - ] + "execution_count": 106 }, { "cell_type": "markdown", @@ -151,13 +892,24 @@ }, { "cell_type": "code", - "execution_count": null, "id": "6a2d0ae9", - "metadata": {}, - "outputs": [], - "source": [ - "# ваш код" - ] + "metadata": { + "ExecuteTime": { + "end_time": "2026-05-01T13:50:23.759842Z", + "start_time": "2026-05-01T13:50:23.753795Z" + } + }, + "source": "print((titanic_data['embark_town']).value_counts().index[0])", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Southampton\n" + ] + } + ], + "execution_count": 107 }, { "cell_type": "markdown", @@ -171,13 +923,292 @@ }, { "cell_type": "code", - "execution_count": null, "id": "11acb4b4", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2026-05-01T13:50:26.023274Z", + "start_time": "2026-05-01T13:50:25.995312Z" + } + }, "source": [ - "# ваш код" - ] + "percent_of_alive = ((titanic_data['alive']).value_counts()['yes'])/len(titanic_data)*100\n", + "\n", + "print(round(percent_of_alive,2))" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "38.25\n" + ] + }, + { + "data": { + "text/plain": [ + " survived pclass sex age sibsp parch fare embarked class \\\n", + "0 0 3 male 22.0 1 0 7.2500 S Third \n", + "1 1 1 female 38.0 1 0 71.2833 C First \n", + "2 1 3 female 26.0 0 0 7.9250 S Third \n", + "3 1 1 female 35.0 1 0 53.1000 S First \n", + "4 0 3 male 35.0 0 0 8.0500 S Third \n", + ".. ... ... ... ... ... ... ... ... ... \n", + "886 0 2 male 27.0 0 0 13.0000 S Second \n", + "887 1 1 female 19.0 0 0 30.0000 S First \n", + "888 0 3 female 30.0 1 2 23.4500 S Third \n", + "889 1 1 male 26.0 0 0 30.0000 C First \n", + "890 0 3 male 32.0 0 0 7.7500 Q Third \n", + "\n", + " who adult_male embark_town alive alone \n", + "0 man True Southampton no False \n", + "1 woman False Cherbourg yes False \n", + "2 woman False Southampton yes True \n", + "3 woman False Southampton yes False \n", + "4 man True Southampton no True \n", + ".. ... ... ... ... ... \n", + "886 man True Southampton no True \n", + "887 woman False Southampton yes True \n", + "888 woman False Southampton no False \n", + "889 man True Cherbourg yes True \n", + "890 man True Queenstown no True \n", + "\n", + "[889 rows x 14 columns]" + ], + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
survivedpclasssexagesibspparchfareembarkedclasswhoadult_maleembark_townalivealone
003male22.0107.2500SThirdmanTrueSouthamptonnoFalse
111female38.01071.2833CFirstwomanFalseCherbourgyesFalse
213female26.0007.9250SThirdwomanFalseSouthamptonyesTrue
311female35.01053.1000SFirstwomanFalseSouthamptonyesFalse
403male35.0008.0500SThirdmanTrueSouthamptonnoTrue
.............................................
88602male27.00013.0000SSecondmanTrueSouthamptonnoTrue
88711female19.00030.0000SFirstwomanFalseSouthamptonyesTrue
88803female30.01223.4500SThirdwomanFalseSouthamptonnoFalse
88911male26.00030.0000CFirstmanTrueCherbourgyesTrue
89003male32.0007.7500QThirdmanTrueQueenstownnoTrue
\n", + "

889 rows × 14 columns

\n", + "
" + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "execution_count": 108 }, { "cell_type": "markdown", @@ -191,13 +1222,32 @@ }, { "cell_type": "code", - "execution_count": null, "id": "59ec7295", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2026-05-01T14:25:27.091483Z", + "start_time": "2026-05-01T14:25:27.082859Z" + } + }, "source": [ - "# ваш код" - ] + "survived = titanic_data['alive']=='yes'\n", + "survived_people_from_cities=titanic_data[survived]['embarked'].value_counts()\n", + "print(survived_people_from_cities)" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "embarked\n", + "S 217\n", + "C 93\n", + "Q 30\n", + "Name: count, dtype: int64\n" + ] + } + ], + "execution_count": 109 }, { "cell_type": "markdown", @@ -211,13 +1261,32 @@ }, { "cell_type": "code", - "execution_count": null, "id": "34daca28", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2026-05-01T15:09:15.486354Z", + "start_time": "2026-05-01T15:09:15.475876Z" + } + }, "source": [ - "# ваш код" - ] + "survived_people_from_classes=titanic_data[survived]['class'].value_counts()\n", + "all_people_from_classes = titanic_data['class'].value_counts()\n", + "print(round(survived_people_from_classes/all_people_from_classes*100, 2))" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "class\n", + "First 62.62\n", + "Second 47.28\n", + "Third 24.24\n", + "Name: count, dtype: float64\n" + ] + } + ], + "execution_count": 114 }, { "cell_type": "markdown", @@ -226,18 +1295,34 @@ "source": [ "### Часть 9\n", "\n", - "Будем считать, что пассажиры, купившие билет **НЕ МЕНЕЕ** чем за $100, считаются богатыми. Определите процент выживших среди богатых пассажиров. Ответ округлите до 2 знаков после запятой. В ответе должно получиться число. " + "Будем считать, что пассажиры, купившие билет **НЕ МЕНЕЕ** чем за $100, считаются богатыми. Определите процент выживших среди богатых пассажиров. Ответ округлите до 2 знаков после запятой. В ответе должно получиться число." ] }, { "cell_type": "code", - "execution_count": null, "id": "1fc0d667", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2026-05-01T15:21:39.287509Z", + "start_time": "2026-05-01T15:21:39.273771Z" + } + }, "source": [ - "# ваш код" - ] + "rich_people = titanic_data['fare']>=100\n", + "survived_rich_people = (rich_people & survived)\n", + "rich_percent_survived=round((len(titanic_data[survived_rich_people]))/len(titanic_data[rich_people])*100, 2)\n", + "print(rich_percent_survived)" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "73.58\n" + ] + } + ], + "execution_count": 124 }, { "cell_type": "markdown", @@ -251,21 +1336,39 @@ }, { "cell_type": "code", - "execution_count": null, "id": "480352b6", - "metadata": {}, - "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2026-05-01T15:30:25.774049Z", + "start_time": "2026-05-01T15:30:25.767251Z" + } + }, "source": [ - "# ваш код" - ] + "alone_kids = (titanic_data['who']=='child') & (titanic_data['alone'])\n", + "print(len(titanic_data[alone_kids]))" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n" + ] + } + ], + "execution_count": 127 }, { "cell_type": "markdown", "id": "aac62cfd", "metadata": {}, - "source": [ - "Какие выводы вы можете сделать о выживших пассажирах Титаника? " - ] + "source": "Какие выводы вы можете сделать о выживших пассажирах Титаника?" + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "Из проведенных операций видно, что выживаемость человека в крушении Титаника коллерировала с его богатством. Комический эффект заключается в том, что даже дети(в количестве 6 штук) смогли позволить себе билеты на Титаник, а я нет. Если задуматься, то это многое говорит о нашем обществе...", + "id": "927509250d592e4a" } ], "metadata": {