【问题标题】:Writing large array to file in python在python中将大数组写入文件
【发布时间】:2018-08-08 23:38:33
【问题描述】:

我有大约 1.7 GB 的手电筒模型,我尝试将此模型写入文件或打印。代码如下:

import numpy
numpy.set_printoptions(threshold=numpy.nan)
import torchfile
o = torchfile.load('ptn_comb.t7')
#print o
numpy.savetxt("test.txt",o)

当我删除“numpy.set_printoptions(threshold=numpy.nan)”打印和 savetxt 运行正常并在 10-15 分钟内终止。但是,使用“numpy.set_printoptions(threshold=numpy.nan)” 即使脚本运行了两个小时,它也不会终止,并且 test.txt 始终为空。

我该如何解决这个问题?谢谢。

【问题讨论】:

  • 打印选项会影响print o,但不会影响savetxt 步骤。

标签: python numpy printing writefile


【解决方案1】:

如果不更改 threshold,print o 将汇总输出(默认为 1000)。完成后(相对较快),savetxt 可以采取行动。它不使用printoptions。它只是迭代行(第一个暗淡)并将格式化的字符串写入文件。

threshold 设置为 nan print 不会汇总。显然数组太大了,需要很长时间才能格式化并最终打印出来。而且它没有绕过savetxt 步骤。

【讨论】:

    猜你喜欢
    • 2021-03-06
    • 1970-01-01
    • 2015-07-07
    • 2019-02-07
    • 2021-09-05
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 2022-11-27
    相关资源
    最近更新 更多