【发布时间】:2013-03-06 23:37:42
【问题描述】:
这是以前的question 在哪里提高python中函数的时间性能我需要找到一种有效的方法来拆分我的文本文件
我有以下文本文件(超过 32 GB)未排序
....................
0 274 593869.99 6734999.96 121.83 1,
0 273 593869.51 6734999.92 121.57 1,
0 273 593869.15 6734999.89 121.57 1,
0 273 593868.79 6734999.86 121.65 1,
0 272 593868.44 6734999.84 121.65 1,
0 273 593869.00 6734999.94 124.21 1,
0 273 593868.68 6734999.92 124.32 1,
0 274 593868.39 6734999.90 124.44 1,
0 275 593866.94 6734999.71 121.37 1,
0 273 593868.73 6734999.99 127.28 1,
.............................
第一列和第二列是网格中 x,y,z 点的位置 ID(例如:0 -273)。
def point_grid_id(x,y,minx,maxy,distx,disty):
"""give id (row,col)"""
col = int((x - minx)/distx)
row = int((maxy - y)/disty)
return (row, col)
(minx, maxx) 是我的网格的原点,大小为distx,disty。 Id 瓦片的数量是
tiles_id = [j for j in np.ndindex(ny, nx)] #ny = number of row, nx= number of columns
from [(0,0),(0,1),(0,2),...,(ny-1,nx-1)]
n = len(tiles_id)
我需要在 n (= len(tiles_id)) 个文件中分割 ~32 GB 文件。
我可以在不排序但读取文件 n 次的情况下执行此操作。出于这个原因,我希望为(0,0) (= tiles_id[0]) 开头的文件找到一种有效的拆分方法。之后我只能读取一次拆分的文件。
【问题讨论】:
-
不使用python怎么样?
-
不确定使用 Python 对这种大小的文件进行排序的效率有多高。
-
那么,我希望你能在它运行的时候读到一些东西。
-
免费周末在山上远足,远离 PC :)。我知道 Python 很慢,但如果算法需要几天时间也没关系
-
@Gianni:
I LOVE Python!!,是的,我看得出来,爱是如此盲目以至于你看不到它的弱点
标签: python performance algorithm sorting optimization