繁体   English   中英

如何将元素列表转换为 n*n 空格分隔排列,其中 n 是列表中的元素数

[英]How to convert a list of elements to n*n space seperated arrangement where n is number of elements in the list

这是我的清单: N= 9 Mylist=[9,8,7,6,5,4,3,2,1]

对于这个输入 Output 应该是:

9 8 7
6 5 4
3 2 1

听起来您想知道如何将列表转换为特定形状的 numpy 数组。 文档在这里

import numpy as np
my_list=[3,9,8,7,6,5,4,3,2,1]
# Dropping the first item of your list as it isn't used in your output
array = np.array(my_list[1:]).reshape((3,3))
print(array)

Output

[[9 8 7]
 [6 5 4]
 [3 2 1]]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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