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