我正在尝试通过转换来自 thunder 的方法来评估 dask (使用 Spark),到等效的 numpy 版本,但我不确定如何使用 dask/distributed 来编写它。
在 thunder 中,我可以拍摄一堆图像,将其转换为一系列图像,并与一些信号相关联:
imgs = thunder.images.fromrandom((10, 900, 900))
series = imgs.toseries()
signal = series[5, 5, :]
correlated = series.correlate(signal)
numpy 版本看起来像这样:
series = numpy.random.rand(900, 900, 10)
signal = series[5, 5, :]
reshaped = series.reshape(900 * 900, 10)
correlated = numpy.asarray(
map(lambda x: numpy.corrcoef(x, signal)[0, 1], reshaped))
)
final = correlated.reshape(900, 900)
我正在寻找一些关于如何将其转换为特别适合分发的东西的技巧。
请您参考如下方法:
也许像下面这样?
import dask.array as da
import numpy as np
imgs = da.random.random((10, 900, 900), chunks=(1, 900, 900))
reshaped = imgs.reshape((10, 900 * 900))
如果你想将你的图像相互关联
result = da.corrcoef(reshaped)
result.compute()
或者针对其他一些信号
signal = np.random.random(900 * 900)
result = reshaped.map_blocks(np.corrcoef, signal, dtype=signal.dtype)
result.compute()
但是,我对您的申请不是很熟悉,所以上面的回复可能有问题。
