我有一个尺寸为nx1008的大二维阵列(通常为0.5到2GB)。此数组包含多个图像,数组中的值实际上是像素值。基本上恢复这些图像的步骤如下
这是我的解决方案
counter=0
dump=np.array([], dtype=np.uint16)
#pixelDat is the array shaped n x 1008 containing the pixel values
for j in xrange(len(pixelDat)):
#Check if it is the last row for a particular image
if(j == (260*(counter+1)+ counter)):
counter += 1
dump=np.append(dump, pixelDat[j][:64])
#Reshape dump to form the image and write it to a fits file
hdu = fits.PrimaryHDU(np.reshape(dump, (512,512)))
hdu.writeto('img'+str("{0:0>4}".format(counter))+'.fits', clobber=True)
#Clear dump to enable formation of next image
dump=np.array([], dtype=np.uint16)
else:
dump=np.append(dump, pixelDat[j])
我一直在想是否有办法加快整个过程。我首先想到的是使用矢量化的numpy操作。但是我不太清楚如何在这种情况下应用它。你知道吗
注:不要担心配合和hdu部分。它只是为我的图像创建一个.fits文件。你知道吗
下面是一个使用展平和
np.split
的尝试。它避免了复制数据。你知道吗相关问题 更多 >
编程相关推荐