'How to add a constant value to every entry in a sparse Dask array in a distributed setting
How can i add a constant value to a Dask sparse array? Simply using the + operator does not work.
Consider the following dask sparse array:
import dask.array as da
import sparse
from dask.distributed import Client
client = Client()
a = da.from_array(sparse.COO(coords=[[0],[0]],data=[1],shape=(2,2)))
print(a.compute())
Gives: <COO: shape=(2, 2), dtype=int32, nnz=1, fill_value=0>
Then, if I add a value:
b = a+1
print(b.compute())
print(b.compute().todense())
It prints:
<COO: shape=(2, 2), dtype=int32, nnz=1, fill_value=0>
[[2 0] [0 0]]
Thus, updating only the data, but not the fill_value. How can I increase the fill_value as well? I also tried the following:
b = a.map_blocks(lambda x: x+1)
But this gives the same result.
Note: This behaviour seems specific to using Client from dask.distributed. When not using this, it seems to work as expected.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
