From 4f7a648b56e0225d78fcbc84255792736b713ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Recep=20Kadir=20Alt=C4=B1nta=C5=9F?= <126012220+kdraltntas@users.noreply.github.com> Date: Sun, 30 Nov 2025 02:16:17 +0300 Subject: [PATCH] Add function to replace center of array with -1 --- ...rays_recepkadir_alt\304\261nta\305\237.py" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "Week04/arrays_recepkadir_alt\304\261nta\305\237.py" diff --git "a/Week04/arrays_recepkadir_alt\304\261nta\305\237.py" "b/Week04/arrays_recepkadir_alt\304\261nta\305\237.py" new file mode 100644 index 0000000..3b78e9e --- /dev/null +++ "b/Week04/arrays_recepkadir_alt\304\261nta\305\237.py" @@ -0,0 +1,20 @@ +import numpy as np + + +def replace_center_with_minus_one(d, n, m): + if m > n or d <= 0 or n < 0 or m < 0: + raise ValueError("Invalid parameters") + + min_val = 10 ** (d - 1) + max_val = 10 ** d + + arr = np.random.randint(min_val, max_val, size=(n, n)) + + start_index = (n - m) // 2 + end_index = start_index + m + + arr[start_index:end_index, start_index:end_index] = -1 + + return arr + +print(replace_center_with_minus_one(2, 5, 3))