简体   繁体   English

Python:使用numpy保存/加载大型数组

[英]Python: Saving / loading large array using numpy

I have saved a large array of complex numbers using python, 我使用python保存了大量的复数,

numpy.save(file_name, eval(variable_name))

that worked without any trouble. 没有任何麻烦的工作。 However, loading, 但是,载入中

variable_name=numpy.load(file_name)

yields the following error, 产生以下错误,

ValueError: total size of new array must be unchanged

Using: Python 2.7.9 64-bit and the file is 1.19 GB large. 使用:Python 2.7.9 64位,文件大小为1.19 GB。

There is no problem with the size of your array, you likely didn't opened your file in the right way, try this: 数组的大小没有问题,您可能没有以正确的方式打开文件,请尝试以下操作:

with open(file_name, "rb") as file_:
    variable_name = np.load(file_)

Alternatively you can use pickle : 或者,您可以使用pickle

import pickle

# Saving:
data_file = open('filename.bi', 'w')
pickle.dump(your_data, data_file)
data_file.close()

# Loading:
data_file = open('filename.bi')
data = pickle.load(data_file)
data_file.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM