NumPy堆栈或将数组追加到数组 [英] NumPy stack or append array to array
本文介绍了NumPy堆栈或将数组追加到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从NumPy开始.
给出两个 np.array
, queu
和 new_path
:
queu = [ [[0 0]
[0 1]]
]
new_path = [ [[0 0]
[1 0]
[2 0]]
]
我的目标是获取以下 queu
:
queu = [ [[0 0]
[0 1]]
[[0 0]
[1 0]
[2 0]]
]
我尝试过:
np.append(queu, new_path, 0)
和
np.vstack((queu, new_path))
但是两者都在提高
除串联轴外,所有输入数组的尺寸都必须完全匹配
all the input array dimensions except for the concatenation axis must match exactly
我没有得到NumPy的哲学.我在做什么错了?
I didn't get the NumPy philosophy. What am I doing wrong?
推荐答案
what you need is np.hstack
In [73]: queu = np.array([[[0, 0],
[0, 1]]
])
In [74]: queu.shape
Out[74]: (1, 2, 2)
In [75]: new_path = np.array([ [[0, 0],
[1, 0],
[2, 0]]
])
In [76]: new_path.shape
Out[76]: (1, 3, 2)
In [81]: np.hstack((queu, new_path))
Out[81]:
array([[[0, 0],
[0, 1],
[0, 0],
[1, 0],
[2, 0]]])
这篇关于NumPy堆栈或将数组追加到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文