python合并表格矩阵并排序_在Python中,将多个列的列表排列成一个矩阵

 2023-09-09 阅读 30 评论 0

摘要:我不知道你是不是从文件里读到了数字块。但假设你已经有了数据。在另外,假设结果块的列数无关,这里的问题是保持数量N。正确的?在block_1 = [[1, 6, 11],[2, 7, 12],python把多个列表合成一个列表。[3, 8, 13],[4, 9, 14],[5, 10, 15]]block_2 =

我不知道你是不是从文件里读到了数字块。但假设你已经有了

数据。在

另外,假设结果块的列数无关,这里的问题是保持数量N。正确的?在block_1 = [

[1, 6, 11],

[2, 7, 12],

python把多个列表合成一个列表。[3, 8, 13],

[4, 9, 14],

[5, 10, 15]

]

block_2 = [

[17, 22, 27],

python 列表合并、[18, 23, 28],

[19, 24, 29],

[20, 25, 30],

[21, 26, 31]

]

all_numbers = []

python合并两个有序列表?new_block = []

rows = len(block_1) # Since the column length is the same.

# Either block_1 or block_2 works here.

# Get all numbers and sort.

for row in block_1:

all_numbers.extend(row)

eval函数python,for row in block_2:

all_numbers.extend(row)

all_numbers.sort()

# Build the matrix.

matrix = []

for i in range(0, len(all_numbers), rows):

python 矩阵。matrix.append(all_numbers[i:i+rows])

# Set the correct place for collumns.

for i in range(len(matrix[0])):

r = []

for j in range(len(matrix)):

r.append(matrix[j][i])

python处理表格。new_block.append(r)

print(new_block)

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/28433.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息