Skip to content

arrays_beyza_sungar.py #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions Week04/arrays_beyza_sungar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import numpy as np

try:
n = int(input("Enter a dimension number (n): "))
if n <= 0:
raise ValueError("n must be a positive integer")

num_digits = int(input("Enter the number of digits for random integers: "))
if num_digits <= 0:
raise ValueError("num_digits must be a positive integer")

m = int(input("Enter the size of the central array (m): "))
if m <= 0:
raise ValueError("m must be a positive integer")
if m > n:
raise ValueError("m cannot be greater than n")
except ValueError as e:
print(f"Error: {e}")
exit()


arr1 = np.random.randint(10 ** (num_digits - 1), 10 ** num_digits, size=(n, n))

#print(arr1)

def change_edge_elements(arr):
n, m = arr.shape
arr[1:n-1, 1:m-1] = -1
return arr

result_array = change_edge_elements(arr1)
print(result_array)