在第4维上连接两个numpy数组 [英] Concatenate two numpy arrays in the 4th dimension
本文介绍了在第4维上连接两个numpy数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个具有三个维度(3 x 4 x 5)的numpy数组,我想将它们连接起来,因此结果具有四个维度(3 x 4 x 5 x 2).在Matlab中,可以使用cat(4, a, b)
完成此操作,但不能在Numpy中完成.
I have two numpy arrays with three dimensions (3 x 4 x 5) and I want to concatenate them so the result has four dimensions (3 x 4 x 5 x 2). In Matlab, this can be done with cat(4, a, b)
, but not in Numpy.
例如:
a = ones((3,4,5))
b = ones((3,4,5))
c = concatenate((a,b), axis=3) # error!
为澄清起见,我希望c[:,:,:,0]
和c[:,:,:,1]
对应于原始的两个数组.
To clarify, I wish c[:,:,:,0]
and c[:,:,:,1]
to correspond to the original two arrays.
推荐答案
那
c = np.stack((a,b), axis=3)
这篇关于在第4维上连接两个numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文