我在磁盘上有一个Numpy
阵列,比我可用的ram大。我可以将它加载为memory-map并使用它没有问题:
a = np.memmap(filename, mode='r', shape=shape, dtype=dtype)
接下来,我可以用类似的方式Following Dask documentation:加载Dask数组
da = da.from_array(np.memmap(filename, shape=shape, dtype=dtype, mode='r'))
如何在此数组中添加行/列
- 理想情况下无需创建全新副本
- 即使必须创建全新的副本,如何处理它(它将不适合RAM)
就像
a2 = np.stack((a, new_a))
将导致整个a
数组加载到内存中,并抛出Out of memory
。
扩展memmap艾德Numpy或Dask数组(大于可用的ram)的最佳方法是什么?
1条答案
按热度按时间bqucvtff1#
我有两个想法。
第一种方法需要创建一个全新的副本,但遵循numpy的基本用法。
第二种方法是简单地复制为二进制文件。使用这种方法,您将追加到第一个文件,因此至少不需要复制第一个文件。
请注意,我假设您的文件不包含头,因为您使用np阅读它们。如果它们确实包含头文件,那么这个过程会变得有点复杂。