[英]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 hackerank array indexing问题描述如下 编写 function array_index 接受三个数字 n,n_row,n_col 并执行下面给出的数组操作
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有人可以帮我完成这个问题的解决方案 PS:附上问题图片以供参考在此处输入图片描述
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:])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.