Block to block operations between 2 dask arrays
Good day friends, I have a question about map_blocks()
. I'm trying something simple, I want to take the dot product between columns (the blocks) of 2 arrays like so:
x=da.random.random((100,5), chunks=(100,1))
y=da.random.random((100,5), chunks=(100,1))
def block_dot_product(a, b):
out=np.dot(a,b)
return out
result=da.map_blocks(block_dot_product, x, y,dtype=np.float64).compute()
If this works as expected it should return a single float for the dot product of each block. So, output should be a single 1x5 array.
I'm clearly missing something because this raises the exception ValueError: shapes (100,1) and (100,1) not aligned: 1 (dim 1) != 100 (dim 0)
Any pointers as to what I'm not understanding???
For future reference: this question was resolved in Slack, https://dask.slack.com/archives/C02282J3Q6Q/p1639506482143700
One way to resolve this (as per Slack) is to use np.squeeze
to make sure that the computed dimensions match the expected dimensions.