MCPcopy Create free account
hub / github.com/dask/dask / from_func

Function from_func

dask/array/core.py:4233–4261  ·  view source on GitHub ↗

Create dask array in a single block by calling a function Calling the provided function with func(*args, **kwargs) should return a NumPy array of the indicated shape and dtype. Examples -------- >>> a = from_func(np.arange, (3,), dtype='i8', args=(3,)) >>> a.compute()

(func, shape, dtype=None, name=None, args=(), kwargs=None)

Source from the content-addressed store, hash-verified

4231
4232
4233def from_func(func, shape, dtype=None, name=None, args=(), kwargs=None):
4234 """Create dask array in a single block by calling a function
4235
4236 Calling the provided function with func(*args, **kwargs) should return a
4237 NumPy array of the indicated shape and dtype.
4238
4239 Examples
4240 --------
4241
4242 >>> a = from_func(np.arange, (3,), dtype='i8', args=(3,))
4243 >>> a.compute()
4244 array([0, 1, 2])
4245
4246 This works particularly well when coupled with dask.array functions like
4247 concatenate and stack:
4248
4249 >>> arrays = [from_func(np.array, (), dtype='i8', args=(n,)) for n in range(5)]
4250 >>> stack(arrays).compute()
4251 array([0, 1, 2, 3, 4])
4252 """
4253 if kwargs is None:
4254 kwargs = {}
4255
4256 name = name or "from_func-" + tokenize(func, shape, dtype, args, kwargs)
4257 if args or kwargs:
4258 func = partial(func, *args, **kwargs)
4259 dsk = {(name,) + (0,) * len(shape): (func,)}
4260 chunks = tuple((i,) for i in shape)
4261 return Array(dsk, name, chunks, dtype)
4262
4263
4264def common_blockdim(blockdims):

Calls 2

ArrayClass · 0.70
tokenizeFunction · 0.50