是否有一种更快的方法可以使用 Dask 只检索大型已发布数组中的单个元素,而不检索整个数组?
在下面的示例中,client.get_dataset('array1')[0] 与 client.get_dataset('array1') 花费的时间大致相同。
import distributed
client = distributed.Client()
data = [1]*10000000
payload = {'array1': data}
client.publish(**payload)
one_element = client.get_dataset('array1')[0]
最佳答案
请注意,您发布的任何内容都会发送给调度程序,而不是发送给工作人员,因此这有点低效。 Publish 旨在与 Dask 集合(例如 dask.array)一起使用。
客户端 1
import dask.array as da
x = da.ones(10000000, chunks=(100000,)) # 1e7 size array cut into 1e5 size chunks
x = x.persist() # persist array on the workers of the cluster
client.publish(x=x) # store the metadata of x on the scheduler
客户端2
x = client.get_dataset('x') # get the lazy collection x
x[0].compute() # this selection happens on the worker, only the result comes down
关于dask - 使用 Dask 访问大型已发布数组中的单个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45225485/