如何将np.memmap的每n行复制到另一个np.memmap?

时间:2018-12-03 10:28:28

标签: python numpy numpy-memmap

我想以最少的内存开销将np.memmap的第n行复制到另一个np.memmap

我尝试过:

mat = np.memmap(input_file, mode='r')
out_mat = np.memmap(output_file, mode='w+', shape=mat[::every_nth_sample].shape)
out_mat[:] = mat[::every_nth_sample]

它将整个垫子加载到内存中。

我也尝试过:

mat = np.memmap(input_file, mode='r')
out_mat = np.memmap(output_file, mode='w+', shape=mat[::every_nth_sample].shape)
for i, r in enumerate(mat[::every_nth_sample]):
    out_mat[i,:] = r

似乎花费了太长时间。有更好的方法吗?

0 个答案:

没有答案
相关问题