'Array Indexing. printing elements of the middle column

hackerank array indexing The Problem description is as follows Write the function array_index which accepts three numbers n,n_row,n_col and performs the array operations given below

  1. Create a array x of shape(n_row,n_col), having first n natural numbers. 2.Print elements of last row
  2. Print elements of middle column. 4.Print elements, overlapping first two rows and last three columns My python code is as follows

import numpy as np
def array_index(n, n_row, n_col):
    
        x = np.arange(n).reshape(n_row, n_col)
        print(x[n_col])
    
if __name__ == '__main__':
        
        n = int(input())
        n_row = int(input())
        n_col = int(input())
        array_index(n, n_row, n_col)

Can someone help me complete the solution for this problem PS: Attached the image of the question for the referenceenter image description here



Solution 1:[1]

import numpy as np
x=np.arange(n).reshape(n_row,n_col)
print(x[-1])
y=int(n_col/2)
print(x[:,y])
print(x[0:2,-3:])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yashvi Malu