簡體   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