[英]Numpy 1d array to 2d array with first element being isolated
我從類似的東西開始
x = np.array([5, 1, 2, 3, 4], [6, 2, 4, 6, 8])
我想要的是這樣的:
x = np.array([5, [[1, 2], [3, 4]], [6, [[2, 4],[6, 8]] ]
我現在有東西
y = np.array([x[0][0], x[0][1:]], [x[1][0], x[1][1:]])
你錯過了[]
x = np.array([[5, 1, 2, 3, 4], [6, 2, 4, 6, 8]])
使用列表理解
[[row[0],row[1:].reshape(2,2).tolist()] for row in x]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.