【发布时间】:2016-06-02 03:15:40
【问题描述】:
我将 numpy 数组保存为原始文件(只有绿色通道,所以没有 RGB):
dtype_string = "float32"
>>> frames.shape
(40000L, 128L, 128L)
frames.astype(dtype_string).tofile(os.path.expanduser('~/Downloads/') + "aligned_" + str(ind) + ".raw")
这是plt.imshow(frames.astype(dtype_string)[400]) 的样子:
你可以下载我保存的raw here
现在我只想打开刚才保存的文件如下:
dat_type= "float32"
with open(g_file, "rb") as file:
frames = np.fromfile(file, dtype=dat_type)
total_number_of_frames = int(np.size(frames)/(width*height))
print("n_frames: "+str(total_number_of_frames))
frames = np.reshape(frames, (total_number_of_frames, width, height))
frames = np.asarray(frames, dtype=dat_type)
但是在这之后plt.imshow(frames[400]) 看起来像这样
为什么我得到平铺图像?
【问题讨论】:
-
保存前
frames.shape是什么,重载后又是什么? -
plt.imshow(frames[400][:][:])的哪个结果?
标签: python-2.7 numpy matplotlib