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
4 changes: 2 additions & 2 deletions homeworks/sem01/hw1/backoff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from random import uniform
from time import sleep
# from random import uniform
# from time import sleep
from typing import (
Callable,
ParamSpec,
Expand Down
Binary file added labyrinth.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added loaded_labyrinth.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
4 changes: 2 additions & 2 deletions requirements-ci.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
matplotlib==3.8.0
numpy==1.26.1
pandas==2.2.2
numpy
pandas

pytest==8.4.2
pytest-cov==7.0.0
Expand Down
Empty file removed solutions/sem01/__init__.py
Empty file.
Empty file.
4 changes: 0 additions & 4 deletions solutions/sem01/lesson02/task1.py

This file was deleted.

4 changes: 0 additions & 4 deletions solutions/sem01/lesson02/task2.py

This file was deleted.

4 changes: 0 additions & 4 deletions solutions/sem01/lesson02/task3.py

This file was deleted.

4 changes: 0 additions & 4 deletions solutions/sem01/lesson02/task4.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson02/task5.py

This file was deleted.

4 changes: 0 additions & 4 deletions solutions/sem01/lesson02/task6.py

This file was deleted.

5 changes: 0 additions & 5 deletions solutions/sem01/lesson02/task7.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson03/task1.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson03/task2.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson03/task3.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson04/task1.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson04/task2.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson04/task3.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson04/task4.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson04/task5.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson04/task6.py

This file was deleted.

Empty file.
3 changes: 0 additions & 3 deletions solutions/sem01/lesson05/task1.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson05/task2.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson05/task3.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson05/task4.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson05/task5.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson05/task6.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson06/task1.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson06/task2.py

This file was deleted.

7 changes: 0 additions & 7 deletions solutions/sem01/lesson06/task3.py

This file was deleted.

3 changes: 0 additions & 3 deletions solutions/sem01/lesson06/task4.py

This file was deleted.

Empty file.
5 changes: 0 additions & 5 deletions solutions/sem01/lesson08/task1.py

This file was deleted.

10 changes: 0 additions & 10 deletions solutions/sem01/lesson08/task2.py

This file was deleted.

Empty file.
10 changes: 0 additions & 10 deletions solutions/sem01/lesson11/task1.py

This file was deleted.

Empty file.
6 changes: 0 additions & 6 deletions solutions/sem01/lesson12/task1.py

This file was deleted.

6 changes: 0 additions & 6 deletions solutions/sem01/lesson12/task2.py

This file was deleted.

12 changes: 0 additions & 12 deletions solutions/sem01/lesson12/task3.py

This file was deleted.

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 lhs.shape != rhs.shape:
raise ShapeMismatchError
return 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
"""
[[[1, 1]]] [[[0, 0]]
[[[1, 1]]] [[0, 0]]]
[[[1, 1]]]
"""
arr = lhs[:, np.newaxis, :] - rhs[np.newaxis, :, :]
return np.sqrt(np.sum(arr**2, axis=2))
21 changes: 19 additions & 2 deletions solutions/sem02/lesson03/task2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,28 @@ 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 (distances.shape == azimuth.shape == inclination.shape):
raise ShapeMismatchError

x = distances * np.sin(inclination) * np.cos(azimuth)
y = distances * np.sin(inclination) * np.sin(azimuth)
z = distances * np.cos(inclination)
return x, y, z


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 (abscissa.shape == ordinates.shape == applicates.shape):
raise ShapeMismatchError

r = np.sqrt(abscissa**2 + ordinates**2 + applicates**2)
az = np.arctan2(ordinates, abscissa)

inc = np.zeros(r.shape)
inc[r != 0] = np.arccos(applicates[r != 0] / r[r != 0])

return r, az, inc
15 changes: 14 additions & 1 deletion solutions/sem02/lesson03/task3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@

def get_extremum_indices(
ordinates: np.ndarray,
) -> tuple[np.ndarray, np.ndarray]: ...
) -> tuple[np.ndarray, np.ndarray]:
if ordinates.size < 3:
raise ValueError

left = ordinates[:-2]
n = ordinates[1:-1]
right = ordinates[2:]

ordinates = np.arange(1, len(ordinates) - 1)

mins = ordinates[((n < left) & (n < right))]
maxs = ordinates[((n > left) & (n > right))]

return mins, maxs
60 changes: 56 additions & 4 deletions solutions/sem02/lesson04/task1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,68 @@


def pad_image(image: np.ndarray, pad_size: int) -> np.ndarray:
# ваш код
return image
if pad_size < 1:
raise ValueError

new_sh = list(image.shape)
new_sh[0] += 2 * pad_size
new_sh[1] += 2 * pad_size

with_pad = np.zeros(new_sh, dtype=image.dtype)

with_pad[
pad_size:-pad_size,
pad_size:-pad_size,
] = image
return with_pad


def blur_image(
image: np.ndarray,
kernel_size: int,
) -> np.ndarray:
# ваш код
return image
if kernel_size < 1 or kernel_size % 2 == 0:
raise ValueError

if kernel_size == 1:
return image

pad_size = kernel_size // 2
with_pad = pad_image(image, pad_size)
h, w = image.shape[:2]

csy = np.cumsum(with_pad, axis=0)
y_sum = np.zeros((h, with_pad.shape[1]) + image.shape[2:])

y_sum[0,] = csy[kernel_size - 1,]
y_sum[1:,] = csy[kernel_size:,] - csy[:-kernel_size,]

csx = np.cumsum(y_sum, axis=1)
xy_sum = np.zeros((h, w) + image.shape[2:])

xy_sum[
:,
0,
] = csx[
:,
kernel_size - 1,
]
xy_sum[
:,
1:,
] = (
csx[
:,
kernel_size:,
]
- csx[
:,
:-kernel_size,
]
)

blur_im = xy_sum / (kernel_size**2)
return blur_im.astype(image.dtype)


if __name__ == "__main__":
Expand Down
28 changes: 26 additions & 2 deletions solutions/sem02/lesson04/task2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ def get_dominant_color_info(
image: np.ndarray[np.uint8],
threshold: int = 5,
) -> tuple[np.uint8, float]:
# ваш код
if threshold < 1:
raise ValueError("threshold must be positive")

return 0, 0
flat = image.flatten()

counts = np.zeros(256, dtype=np.int64)
colors = np.arange(256, dtype=np.int32).reshape(-1, 1)

np.add.at(counts, flat, 1)

valid_colors = counts > 0

diffs = np.abs(colors - colors.T)
mask = diffs < threshold

groups = np.sum(mask * counts, axis=1)

scores = groups * (image.size + 1) + counts

scores[~valid_colors] = -1

ans_ind = np.argmax(scores)

ans = np.uint8(ans_ind)
percent = float(groups[ans_ind] / image.size)

return ans, percent
Loading
Loading