在我的程序中,我当前创建了一个充满零的 numpy 数组,然后 for 循环遍历每个元素,并将其替换为所需的值。有没有更有效的方法来做到这一点?
下面是我正在做的一个例子,而不是一个 int 我有一个需要放入 numpy 数组的每一行的列表。有没有办法替换整行,效率更高。
import numpy as np
from tifffile import imsave
image = np.zeros((5, 2160, 2560), 'uint16')
num =0
for pixel in np.nditer(image, op_flags=['readwrite']):
pixel = num
num += 1
imsave('multipage.tif', image)