简体   繁体   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

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

For this input Output should be:对于这个输入 Output 应该是:

9 8 7
6 5 4
3 2 1

It sounds like you're wondering how to turn a list into a numpy array of a particular shape.听起来您想知道如何将列表转换为特定形状的 numpy 数组。 Documentation is here . 文档在这里

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 Output

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

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

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