我无法从二进制文件加载数组。我做错什么了?

pic = imread('headey-640.bmp')
save('test.in.npy', pic)
f = open('test.in.npy','r')
A = load(f)

---------------------------------------------------------------------------
ValueError: total size of new array must be unchanged

最佳答案

必须以二进制模式打开文件:

import numpy as np

x = np.array([1,2,3])
np.save("test.npy", x)

with open("test.npy", "rb") as npy:
    a = np.load(npy)

关于python - 无法使用numpy load()加载数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28141906/

10-10 15:13