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



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

对于此输入输出应为:

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)

输出

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

最新更新