-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Closed
Copy link
Labels
Description
It was unclear to me from the documentation on dask.array.ones() whether this was expected or unexpected behaviour. If this is expected behaviour, I'd like to clarify it in the docs.
dask.array.ones() and dask.array.zeros() do not accept dask arrays as input, but will accept input numpy arrays.
In contrast, dask.array.ones_like() and dask.array.zeros_like() will both happily accept input dask arrays.
import dask.array as da
import numpy as np
x = np.array([3, 3])
d = da.from_array(x, chunks=2)
da.ones(x, chunks=2)
# output is as expected
# dask.array<ones, shape=(3, 3), dtype=float64, chunksize=(2, 2)>
da.ones(d, chunks=2)
# an error occurs, even before attempting .compute()
# ValueError: The truth value of a Array is ambiguous
# see full traceback belowTraceback:
ValueError Traceback (most recent call last)
<ipython-input-99-3200d4255dc8> in <module>
----> 1 da.ones(d, chunks=2)
c:\users\genevieb\documents\github\dask-hacking\dask\dask\array\wrap.py in wrap_func_shape_as_first_arg(func, *args, **kwargs)
38 dtype = np.dtype(dtype)
39
---> 40 chunks = normalize_chunks(chunks, shape, dtype=dtype)
41 name = kwargs.pop('name', None)
42
c:\users\genevieb\documents\github\dask-hacking\dask\dask\array\core.py in normalize_chunks(chunks, shape, limit, dtype, previous_chunks)
1913 chunks = sum((blockdims_from_blockshape((s,), (c,))
1914 if not isinstance(c, (tuple, list)) else (c,)
-> 1915 for s, c in zip(shape, chunks)), ())
1916 for c in chunks:
1917 if not c:
c:\users\genevieb\documents\github\dask-hacking\dask\dask\array\core.py in <genexpr>(.0)
1913 chunks = sum((blockdims_from_blockshape((s,), (c,))
1914 if not isinstance(c, (tuple, list)) else (c,)
-> 1915 for s, c in zip(shape, chunks)), ())
1916 for c in chunks:
1917 if not c:
c:\users\genevieb\documents\github\dask-hacking\dask\dask\array\core.py in blockdims_from_blockshape(shape, chunks)
757 if shape is None:
758 raise TypeError("Must supply shape= keyword argument")
--> 759 if np.isnan(sum(shape)) or np.isnan(sum(chunks)):
760 raise ValueError("Array chunk sizes are unknown. shape: %s, chunks: %s"
761 % (shape, chunks))
c:\users\genevieb\documents\github\dask-hacking\dask\dask\array\core.py in __bool__(self)
1076 raise ValueError("The truth value of a {0} is ambiguous. "
1077 "Use a.any() or a.all()."
-> 1078 .format(self.__class__.__name__))
1079 else:
1080 return bool(self.compute())
ValueError: The truth value of a Array is ambiguous. Use a.any() or a.all().Reactions are currently unavailable