簡體   English   中英

如何追加或連接或合並兩個以上的numpy數組?

[英]How can I append or concatenate or merge more than 2 numpy arrays?

我有這種形狀的4個numpy數組

(1, 2, 1, 1, 1, 5, 2, 14)
(1, 2, 1, 1, 1, 5, 2, 14)
(1, 2, 1, 1, 1, 5, 2, 14)
(1, 2, 1, 1, 1, 5, 2, 14)

我想將它們合並為一個數組。 形狀為:

(4, 2, 1, 1, 1, 5, 2, 14)

試驗1

np.append(f1, f2, axis=0)的形狀為(2, 2, 1, 1, 1, 5, 2, 14) np.append(f1, f2, axis=0) (2, 2, 1, 1, 1, 5, 2, 14)

我怎樣才能做到這一點?

還是有另一種方式來管理這些數據?

我唯一可以確定的是,這4個數組的形狀相同。

試用2

np.concatenate(f1, f2, f3)

錯誤:

----> 1 np.concatenate(f1, f2, f3)

TypeError: only integer scalar arrays can be converted to a scalar index

將數組放入列表中,然后使用np.concatenate

import numpy as np
l = [np.ones((1, 2, 1, 1, 1, 5, 2, 14))] * 4
a = np.concatenate(l, axis=0)
a.shape
Out[9]: (4, 2, 1, 1, 1, 5, 2, 14)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM