I would like to use dask to do the following operation; let say I have a numpy array:
In: x = np.arange(5)
Out: [0,1,2,3,4]
Then I want a function to map np.arange to all the elements of my array.
I have already defined a function for that purpose:
def list_range(array, no_cell):
return np.add.outer(array, np.arange(no_cell)).T
# e.g
In: list_range(x,3)
Out: array([[0, 1, 2, 3, 4],
[1, 2, 3, 4, 5],
[2, 3, 4, 5, 6]])
Now I want to reproduce this in parallel using map_blocks on a dask array but I always get an error. Here is my attempt based on the dask documentation of map_blocks:
constant = 4
d = da.arange(5, chunks=(2,))
f = da.core.map_blocks(list_range, d, constant, chunks=(2,))
f.compute()
I get
ValueError: could not broadcast input array from shape (4,2) into shape (4)