题目标题:
二维数组转置
题目描述:
编程实现使给定的一个N×M的二维整型数组转置,即行列互换。
输入描述:
第一行是两个整数N和M ,接下来N行整数,每行包含M个整数。整数之间用空格隔开
输出描述:
输出转置后的二维整型数组.每一个数据之间用一个空格隔开,但每行的最后一个数据后不能有空格.所有输出的最后一行不能有回车
样式输入:
2 3
1 2 3
4 5 6
样式输出:
1 4
2 5
3 6
import numpy as np R = int(input("Enter the number of rows:")) C = int(input("Enter the number of columns:")) print("Enter the entries in a single line (separated by space): ") # User input of entries in a # single line separated by space entries = list(map(int, input().split())) # For printing the matrix matrix = np.array(entries).reshape(R, C) print(list(map(list, zip(*matrix)))) ''' Enter the number of rows:3 Enter the number of columns:4 Enter the entries in a single line (separated by space): 1 2 3 4 5 6 7 8 9 0 1 2 [[1, 5, 9], [2, 6, 0], [3, 7, 1], [4, 8, 2]]'''