无法加载numpy load()的数组

时间:2015-01-25 21:44:13

标签: python numpy

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

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

1 个答案:

答案 0 :(得分:4)

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

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)