【发布时间】:2021-02-07 12:05:12
【问题描述】:
我有一个巨大的 2D numpy 数组 (dtype=bool) 和一个缓冲区,我想将这个 2D 数组写入缓冲区。目前,我执行以下操作,
# Python version 3.7.7, NumPy version 1.18.5
# shape in the dummy_array is just an example, sometimes will be bigger
dummy_array = np.array(np.empty((599066148, 213), dtype='bool'), dtype='bool')
# Pyarrow plasma store buffer
buf = client.create(object_id, dummy_array.nbytes)
# Get a NumPy view of the buffer
array = np.frombuffer(buf, dtype="bool").reshape(dummy_array.shape)
# Write the data or the NumPy array to the buffer
array[:] = dummy_array
问题是这至少需要 3 分钟。 dummy_array 的大小通常为 100 到 200GB,有时甚至更多。我无法弄清楚如何使用memoryview 和np.ctypeslib.as_array(buf, shape=dummy_array.shape) 来执行此操作,正如question 中提到的二维数组(我试过,但没有用)。任何以更好或更快的方式执行此操作的指针都会很棒,因为我将这样做至少数百次,因此,每次迭代节省 30 到 60 秒甚至可以节省数小时。
【问题讨论】:
-
那么您是在具有 200+ GB RAM 的节点上运行它的吗?
-
@MateenUlhaq 是的,一个计算服务器。它有 1TB 内存。
标签: python numpy multiprocessing shared-memory pyarrow