简体   繁体   中英

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 reference enter image description here

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:])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM