Print a array of size n*n, with borders as 1's and fill rest of element with 0's Assessment Question: Print an array of size n*n, with border as 1's and rest of the element as 0's.
Sample Input: 5
Sample Output:
[[1 1 1 1 1]
 [1 0 0 0 1]
 [1 0 0 0 1]
 [1 0 0 0 1]
 [1 1 1 1 1]]

Here is my solution:
import numpy as np
n = int(input(&quot;Enter a number:&quot;))
np_box = np.zeros([n, n], dtype='int')
np_box[:, 0] = np_box[:, -1] = np_box[0] = np_box[-1] = 1
print(np_box)  

Can this code be still optimised (using numpy, considering space and time complexity)?
Have you alread checked out np.pad?
import numpy as np
n = int(input(&quot;Enter a number:&quot;))
np_box = np.pad(np.zeros((n-1,n-1)), 1, constant_values=1)