From 0ff290d424d1e5bdeedbccbaf5303196736ce6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=B6zge?= <162044805+ozgeucr@users.noreply.github.com> Date: Sat, 8 Nov 2025 15:22:35 +0300 Subject: [PATCH] Add function to replace center of array with -1 --- Week04/arrays_ozge_ucar.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Week04/arrays_ozge_ucar.py diff --git a/Week04/arrays_ozge_ucar.py b/Week04/arrays_ozge_ucar.py new file mode 100644 index 0000000..831d399 --- /dev/null +++ b/Week04/arrays_ozge_ucar.py @@ -0,0 +1,17 @@ +import numpy as np +def replace_center_with_minus_one(d, n, m): + if m > n: + raise ValueError() + if d <= 0: + raise ValueError() + if n <= 0 or m <= 0: + raise ValueError() + + max_value = 10 ** d - 1 + main_array = np.random.randint(low=0, high=max_value + 1, size=(n, n)) + + start_index = (n - m) // 2 + end_index = start_index + m + main_array[start_index:end_index, start_index:end_index] = -1 + + return main_array