gpt4 book ai didi

python - 如何将多个 numpy 2d 数组堆叠到一个 3d 数组中?

转载 作者:行者123 更新时间:2023-12-01 01:20:28 24 4
gpt4 key购买 nike

这是我的代码:

img = imread("lena.jpg")
for channel in range(3):
res = filter(img[:,:,channel], filter)
# todo: stack to 3d here

正如您所看到的,我正在为图片中的每个 channel 应用一些过滤器。如何将它们堆叠回 3d 数组? (=原始图像形状)

谢谢

最佳答案

您可以使用np.dstack :

import numpy as np

image = np.random.randint(100, size=(100, 100, 3))

r, g, b = image[:, :, 0], image[:, :, 1], image[:, :, 2]

result = np.dstack((r, g, b))

print("image shape", image.shape)
print("result shape", result.shape)

输出

image shape (100, 100, 3)
result shape (100, 100, 3)

关于python - 如何将多个 numpy 2d 数组堆叠到一个 3d 数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53889708/

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