简体   繁体   English

重塑和融合4D至3D阵列

[英]Reshape and conccatente arrays in 4D to 3D

l'm working with 4D arrays in numpy. 我正在使用numpy中的4D数组。 l would like to append the data in forth dimension as follow : 我想将数据附加到第四维,如下所示:

1) inputs : 1)输入:

data_1_1=dim(2,4,130,10)
data_1_2=dim(2,4,130,10)

expected output : 预期产量:

data_1=dim(2,4,130,20)

2) reduce 4D array to 3D array inputs : 2)将4D数组简化为3D数组输入:

data_2_1=dim(3,5,130,20)

expected output : 预期产量:

data_2_1=dim(15,130,20)

Sorry for my newbie question. 对不起,我的新手问题。

Thank you for your help 谢谢您的帮助

What l have tried ? 我尝试了什么? 1) 1)

data_1= np.concatenate((data_1_1[...,np.newaxis],data_1_2[...,np.newaxis]),axis=2)

l'm wondering if this solution do the right job. 我想知道这种解决方案是否做得对。 since l would like to concatenate on the last dimension. 因为我想在最后一个维度上串联。 In which order it's done ? 以什么顺序完成的? Is is correct ? 是正确的吗?

2) For this case l don't have any idea 2)对于这种情况我不知道

For the first part you need to say you want a specific axis to work on: 对于第一部分,您需要说要在特定轴上工作:

>>>x=np.arange(2*4*130*10).reshape(2,4,130,10)
>>>np.concatenate((x,x),axis=3).shape
(2, 4, 130, 20)

and for the second part, sounds like you want a reshape 第二部分听起来像是您需要重塑

>>>y=np.arange(3*5*130*20).reshape(3,5,130,20)
>>> y.reshape(15,130,20).shape
(15, 130, 20)

The numpy terms you need to acquaint yourself with are axis and shape - a good read on these will help you a lot. 您需要熟悉的numpy是轴和形状-仔细阅读这些内容将对您有很大帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM