a***a 发帖数: 92 | 1 文本文件很大,一个一个的数据读入python,加入一个list速度太慢,有没有可能一下
子全部读入一个list |
r****t 发帖数: 10904 | |
w****i 发帖数: 964 | 3 if u have enough memory, use readlines() to read all the data and then use
list comprehension to convert to whatever you need.
Or you can save the data in Pickles and use cPickle.load. (but i doubt this
will be faster than the first way.) |
r****t 发帖数: 10904 | 4 cPickle can be much faster, no doubt. |
a**a 发帖数: 416 | 5 well, if dumped as binary, yes, flashing speed!
【在 r****t 的大作中提到】 : cPickle can be much faster, no doubt.
|
a***a 发帖数: 92 | |
a***a 发帖数: 92 | 7 还有个问题,就是cpickle输出的数据在txt看,很奇怪,如果要c++来读,貌似读不出
来。有没有什么办法?还是说要转换数据?
【在 a***a 的大作中提到】 : 文本文件很大,一个一个的数据读入python,加入一个list速度太慢,有没有可能一下 : 子全部读入一个list
|
w****i 发帖数: 964 | 8 pickle is for python only,
if you need to read it in C++ too, you can use either plain text, or
standard binary format of floats, (e.g., use numpy.fromfile() in python) |
a***a 发帖数: 92 | 9 我用的是txt file,因为数据很大,所以c++读起来挺费时间的
二进制会快点么?
【在 w****i 的大作中提到】 : pickle is for python only, : if you need to read it in C++ too, you can use either plain text, or : standard binary format of floats, (e.g., use numpy.fromfile() in python)
|
k**f 发帖数: 92 | 10 二进制肯定快的,不需要转换,直接就读入内存
【在 a***a 的大作中提到】 : 我用的是txt file,因为数据很大,所以c++读起来挺费时间的 : 二进制会快点么?
|
a***a 发帖数: 92 | 11 那二进制输入c++以后,就可以和普通十进制一样写,还是说要先转换 |
r****t 发帖数: 10904 | |
a***a 发帖数: 92 | 13 因为python计算速度不如c++...所以要参杂一点c++ |
r****t 发帖数: 10904 | 14 所以你就花时间写这些 input/output code? |