gpt4 book ai didi

python - 将更高维度的立方体与二维数组进行卷积

转载 作者:行者123 更新时间:2023-11-28 17:59:55 25 4
gpt4 key购买 nike

我正在将形状为 [nLambda,nX,nY] 的 3D 数据立方体与形状为 [nLambda,3] 的过滤器进行卷积。我设法让它适用于这种情况,但我需要对大量保存为 [nt,nLambda,nX,nY] 的立方体重复此过程。我想扩展我必须处理的代码,但我一直在搞乱平铺。有谁知道如何做到这一点?

我当前的程序:

datacube.shape         = [21,100,100]
filters.shape = [21,3]
data_collapsed.shape = [100,100,3]

我想要它做

datacube.shape         = [10,21,100,100]
filters.shape = [21,3]
data_collapsed.shape = [10,100,100,3]

我用于 3D 立方体的代码

nl,nx,ny = datacube.shape
filter_rgb = np.tile(filters, (ny,nx,1,1))
filter_rgb = np.swapaxes(filter_rgb, 0,2)
data_rgb = np.tile(datacube,(3,1,1,1))
data_rgb = np.swapaxes(data_rgb,0,-1)
data_filtered = data_rgb * filter_rgb
data_collapsed = np.sum(data_filtered, axis=0)

最佳答案

您可以使用 np.tensordot .

对于 datacube 作为 4D 的情况 -

data_collapsed = np.tensordot(datacube,filters,axes=(1,0))

对于 3D 案例 -

data_collapsed = np.tensordot(datacube,filters,axes=(0,0))

Related post to understand tensordot .

关于python - 将更高维度的立方体与二维数组进行卷积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56163779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com