这是一个之前的问题,在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)
我需要将大小约为32GB的文件切片成n(=len(tiles_id))
个文件。
虽然可以不用排序就读取文件n次,但出于这个原因,我希望找到一种从(0,0) (= tiles_id[0])
开始的高效分割方法。之后,我只需要读取一次已经切割好的文件。
我喜欢Python!!
,是啊,我能看出来,爱情是如此盲目,以至于你看不到它的弱点。 - Abhijit