下面的代码实现了我想要实现的目标,但是使用的是python列表,效率可能非常低。请让我知道有没有办法完全用Numpy来做以下事情:
def makeImageArray(count):
l = []
for i in range (count):
l.append(image)
res = np.array(l)
return res其中image是形状(1200,1200,3)的数值数组。
非常感谢!
发布于 2021-03-07 02:23:10
可以使用numpy.stack() (reference)
如果您有多个要添加到新数组中的图像,您可以使用以下命令
import numpy as np
image_0 = np.random.rand(1200,1200,3)
image_1 = np.random.rand(1200,1200,3)
stack = np.stack((image_0, image_1))
stack.shape
>>> (2, 1200, 1200, 3)如果您只想多次堆叠一个数组
编辑
如果您想堆叠相同的图像:
image = np.random.rand(1200,1200,3)
count = 10
stack = np.stack([image for _ in range(count)])
stack.shape
>>> (10, 1200, 1200, 3)发布于 2021-03-07 02:27:03
arr = np.array([image for x in range(count)])
return arrhttps://stackoverflow.com/questions/66509039
复制相似问题