简体   繁体   English

使用 Python 保存大 numpy arrays

[英]Saving large numpy arrays using Python

I have a dataframe with only two columns, one is text and one is with numpy array values, which can have more than 170000 elements.我有一个 dataframe 只有两列,一列是文本,一列是 numpy 数组值,它可以有超过 170000 个元素。 The problem is how to save this large numpy arrays as files, so I can load them back later.问题是如何将这个大的 numpy arrays 保存为文件,以便稍后将它们加载回来。 When trying to save as CVS, it just saves it as a short string, loosing the real values:当尝试另存为 CVS 时,它只是将其保存为一个短字符串,而丢失了实际值:

[-8.0152120e-07  2.8887976e-05  3.3898741e-05 ... -1.3205040e-01
 -9.4032057e-02  0.0000000e+00]

I thought maybe to save as text one by one, but is there any elegant way to do this?我想也许可以一个一个地保存为文本,但是有什么优雅的方法可以做到这一点吗?

As suggested, you can save it as a numpy file using np.save .按照建议,您可以使用np.save将其保存为 numpy 文件。 Later you can load it using np.load .稍后您可以使用np.load加载它。

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

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