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

Function from_func

dask/array/core.py:4237–4265  ·  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

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

Calls 2

ArrayClass · 0.70
tokenizeFunction · 0.50