Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deprecated_tests/sem02/tests/task3/test_lesson03_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_get_mutual_l2_distances(self, lhs: list, rhs: list):
)
def test_get_mutual_l2_distances_validate(self, lhs: list, rhs: list):
with pytest.raises(Task1ShapeMismatchError):
sum_arrays_vectorized(np.array(lhs), np.array(rhs))
get_mutual_l2_distances_vectorized(np.array(lhs), np.array(rhs))


class TestTask2:
Expand Down
2 changes: 0 additions & 2 deletions homeworks/sem01/hw1/backoff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from random import uniform
from time import sleep
from typing import (
Callable,
ParamSpec,
Expand Down
Binary file added modulated_signal.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions requirements-ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ pandas==2.2.2
pytest==8.4.2
pytest-cov==7.0.0
ruff==0.13.0

pillow==11.1.0
2 changes: 1 addition & 1 deletion solutions/sem01/lesson02/task3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def get_amount_of_ways_to_climb(stair_amount: int) -> int:
step_prev, step_curr = 1, 1
step_curr = 1
# ваш код
return step_curr
2 changes: 1 addition & 1 deletion solutions/sem01/lesson03/task1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def flip_bits_in_range(num: int, left_bit: int, right_bit: int) -> int:
# ваш код
return num
return num
2 changes: 1 addition & 1 deletion solutions/sem01/lesson03/task2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def get_cube_root(n: float, eps: float) -> float:
# ваш код
return n
return n
2 changes: 1 addition & 1 deletion solutions/sem01/lesson04/task1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def is_arithmetic_progression(lst: list[list[int]]) -> bool:
# ваш код
return False
return False
2 changes: 1 addition & 1 deletion solutions/sem01/lesson04/task2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def merge_intervals(intervals: list[list[int, int]]) -> list[list[int, int]]:
# ваш код
return [[0,0]]
return [[0, 0]]
2 changes: 1 addition & 1 deletion solutions/sem01/lesson04/task4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def move_zeros_to_end(nums: list[int]) -> list[int]:
# ваш код
return 0
return 0
2 changes: 1 addition & 1 deletion solutions/sem01/lesson04/task5.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def find_row_with_most_ones(matrix: list[list[int]]) -> int:
# ваш код
return 0
return 0
4 changes: 2 additions & 2 deletions solutions/sem01/lesson04/task6.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def count_cycles(arr: list[int]) -> int:
def count_cycles(arr: list[int]) -> int:
# ваш код
return 0
return 0
2 changes: 1 addition & 1 deletion solutions/sem01/lesson05/task1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def is_palindrome(text: str) -> bool:
# ваш код
return False
return False
2 changes: 1 addition & 1 deletion solutions/sem01/lesson05/task2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def are_anagrams(word1: str, word2: str) -> bool:
# ваш код
return False
return False
2 changes: 1 addition & 1 deletion solutions/sem01/lesson05/task4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def unzip(compress_text: str) -> str:
# ваш код
return compress_text
return compress_text
4 changes: 2 additions & 2 deletions solutions/sem01/lesson05/task5.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def reg_validator(reg_expr: str, text: str) -> bool:
def reg_validator(reg_expr: str, text: str) -> bool:
# ваш код
return False
return False
2 changes: 1 addition & 1 deletion solutions/sem01/lesson05/task6.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def simplify_path(path: str) -> str:
# ваш код
return path
return path
2 changes: 1 addition & 1 deletion solutions/sem01/lesson06/task1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def int_to_roman(num: int) -> str:
# ваш код
return ""
return ""
2 changes: 1 addition & 1 deletion solutions/sem01/lesson06/task2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def get_len_of_longest_substring(text: str) -> int:
# ваш код
return 0
return 0
1 change: 0 additions & 1 deletion solutions/sem01/lesson06/task3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ def is_there_any_good_subarray(
nums: list[int],
k: int,
) -> bool:

# ваш код
return False
2 changes: 1 addition & 1 deletion solutions/sem01/lesson06/task4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def count_unique_words(text: str) -> int:
# ваш код
return 0
return 0
3 changes: 2 additions & 1 deletion solutions/sem01/lesson08/task1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Callable


def make_averager(accumulation_period: int) -> Callable[[float], float]:
# ваш код
pass
pass
8 changes: 3 additions & 5 deletions solutions/sem01/lesson08/task2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
pass
3 changes: 0 additions & 3 deletions solutions/sem01/lesson12/task3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sys


class FileOut:
def __init__(
self,
Expand Down
19 changes: 16 additions & 3 deletions solutions/sem02/lesson03/task1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ class ShapeMismatchError(Exception):
def sum_arrays_vectorized(
lhs: np.ndarray,
rhs: np.ndarray,
) -> np.ndarray: ...
) -> np.ndarray:
if len(lhs) != len(rhs):
raise ShapeMismatchError
return lhs + rhs


def compute_poly_vectorized(abscissa: np.ndarray) -> np.ndarray: ...
def compute_poly_vectorized(abscissa: np.ndarray) -> np.ndarray:
return np.power(abscissa, 2) * 3 + abscissa * 2 + 1


def get_mutual_l2_distances_vectorized(
lhs: np.ndarray,
rhs: np.ndarray,
) -> np.ndarray: ...
) -> np.ndarray:
if lhs.shape != rhs.shape:
raise ShapeMismatchError
return [
[
sum((lhs[i][k] - rhs[j][k]) ** 2 for k in range(len(lhs[0]))) ** 0.5
for j in range(len(rhs))
]
for i in range(len(lhs))
]
18 changes: 16 additions & 2 deletions solutions/sem02/lesson03/task2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,25 @@ 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 not (len(distances) == len(azimuth) == len(inclination)):
raise ShapeMismatchError
return (
distances * np.sin(inclination) * np.cos(azimuth),
distances * np.sin(inclination) * np.sin(azimuth),
distances * np.cos(inclination),
)


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 not (len(abscissa) == len(ordinates) == len(applicates)):
raise ShapeMismatchError
return (
np.sqrt(np.power(abscissa, 2) + np.power(ordinates, 2) + np.power(applicates, 2)),
np.arctan2(ordinates, abscissa),
np.arctan2(np.sqrt(abscissa**2 + ordinates**2), applicates),
)
8 changes: 7 additions & 1 deletion solutions/sem02/lesson03/task3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import numpy as np

MIN_ELEM_COUNT = 3


def get_extremum_indices(
ordinates: np.ndarray,
) -> tuple[np.ndarray, np.ndarray]: ...
) -> tuple[np.ndarray, np.ndarray]:
if len(ordinates) < MIN_ELEM_COUNT:
raise ValueError
left, x, right = ordinates[:-2], ordinates[1:-1], ordinates[2:]
return (np.where((left > x) & (x < right))[0] + 1, np.where((left < x) & (x > right))[0] + 1)
43 changes: 39 additions & 4 deletions solutions/sem02/lesson04/task1.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,52 @@
import numpy as np

MIN_PAD_SIZE = 1
MIN_KERNEL_SIZE = 1


def pad_image(image: np.ndarray, pad_size: int) -> np.ndarray:
# ваш код
return image
if pad_size < MIN_PAD_SIZE:
raise ValueError
shp = image.shape
if len(shp) == 2:
new_shp = (shp[0] + 2 * pad_size, shp[1] + 2 * pad_size)
padded_image = np.zeros(shape=new_shp, dtype=image.dtype)
for i in range(shp[0]):
for j in range(shp[1]):
padded_image[i + pad_size, j + pad_size] = image[i, j]
else:
new_shp = (shp[0] + 2 * pad_size, shp[1] + 2 * pad_size, shp[2])
padded_image = np.zeros(shape=new_shp, dtype=image.dtype)
for i in range(shp[0]):
for j in range(shp[1]):
for k in range(shp[2]):
padded_image[i + pad_size, j + pad_size, k] = image[i, j, k]
return padded_image


def blur_image(
image: np.ndarray,
kernel_size: int,
) -> np.ndarray:
# ваш код
return image
if (kernel_size < MIN_KERNEL_SIZE) or (kernel_size % 2 == 0):
raise ValueError
if kernel_size == 1:
return image
shp = image.shape
pad = kernel_size // 2
image = pad_image(image, pad)
blured_image = np.zeros(shape=shp, dtype=image.dtype)
if len(shp) == 2:
for i in range(shp[0]):
for j in range(shp[1]):
kemel = image[i : i + kernel_size, j : j + kernel_size]
blured_image[i, j] = np.mean(kemel)
else:
for i in range(shp[0]):
for j in range(shp[1]):
kemel = image[i : i + kernel_size, j : j + kernel_size, :]
blured_image[i, j, :] = np.mean(kemel, axis=(0, 1))
return blured_image


if __name__ == "__main__":
Expand Down
20 changes: 17 additions & 3 deletions solutions/sem02/lesson04/task2.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import numpy as np

MINIMAL_THRESHOLD = 1


def get_dominant_color_info(
image: np.ndarray[np.uint8],
threshold: int = 5,
) -> tuple[np.uint8, float]:
# ваш код

return 0, 0
if threshold < MINIMAL_THRESHOLD:
raise ValueError("threshold must be positive")
all_possibals = np.full(shape=256, fill_value=-42, dtype=int)
image = image.reshape(-1)
for pixel in range(0, 256):
if pixel in image:
all_possibals[pixel] = 0
mask = (image > pixel) & ((image - pixel) < threshold) | (image <= pixel) & (
(pixel - image) < threshold
)
all_possibals[pixel] += np.sum(mask)
return (
np.uint8(np.argmax(all_possibals)),
all_possibals[np.argmax(all_possibals)] / image.size,
)
10 changes: 9 additions & 1 deletion solutions/sem02/lesson05/task1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ def can_satisfy_demand(
costs: np.ndarray,
resource_amounts: np.ndarray,
demand_expected: np.ndarray,
) -> bool: ...
) -> bool:
if costs.size != resource_amounts.size * demand_expected.size:
raise ShapeMismatchError
spends = [0] * resource_amounts.size
for j in range(demand_expected.size):
amount = demand_expected[j]
for i in range(resource_amounts.size):
spends[i] += amount * costs[i][j]
return np.all(spends <= resource_amounts)
12 changes: 11 additions & 1 deletion solutions/sem02/lesson05/task2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ 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]:
shp = matrix.shape
if not (shp[0] == shp[1] and shp[0] == vector.size):
raise ShapeMismatchError
if not (np.linalg.matrix_rank(matrix) == shp[0]):
return (None, None)
proj, orth = [], []
for base in matrix:
proj.append((base @ vector) * base / (np.linalg.norm(base) ** 2))
orth.append(vector - (base @ vector) * base / (np.linalg.norm(base) ** 2))
return (np.array(proj), np.array(orth))
7 changes: 6 additions & 1 deletion solutions/sem02/lesson05/task3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ def adaptive_filter(
Vs: np.ndarray,
Vj: np.ndarray,
diag_A: np.ndarray,
) -> np.ndarray: ...
) -> np.ndarray:
if not (Vs.shape[0] == Vj.shape[0] and Vj.shape[1] == diag_A.shape[0]):
raise ShapeMismatchError
return Vs - Vj @ np.linalg.inv(
np.eye(diag_A.size) + np.transpose(np.conj(Vj)) @ Vj @ np.diag(diag_A)
) @ (np.transpose(np.conj(Vj)) @ Vs)
Loading
Loading