使用numpython内存映射提取文件

2024-05-14 12:54:09 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试使用numpy的memmap从一个大文件中提取样本:

# indices - boolean vector indicating which lines we want to extract

file_big = np.memmap('path_big_file',dtype='int16',shape=(indices.shape[0],L))

file_small = np.memmap('new_path_for_small_file',dtype='int16',shape=(indices.sum(),L))

预期的结果是,将创建一个新文件,其中只包含索引标识的部分数据

# place data in files:
file_small[:] = file_big[indices]

以上是手册中描述的程序。它不工作-称为没有足够的内存,即使内存不应该是一个问题:只使用memmap而不上传数据


Tags: 文件数据path内存numpynpfilesmall

热门问题