blosc2.lazyexpr#
- blosc2.lazyexpr(expression: str | bytes | LazyExpr, operands: dict | None = None, out: NDArray | ndarray = None, where: tuple | list | None = None, local_dict: dict | None = None, global_dict: dict | None = None) LazyExpr #
Get a LazyExpr from an expression.
- Parameters:
expression¶ (str or bytes or LazyExpr) – The expression to evaluate. This can be any valid expression that can be ingested by numexpr. If a LazyExpr is passed, the expression will be updated with the new operands.
operands¶ (dict) – The dictionary with operands. Supported values are NumPy.ndarray, Python scalars, NDArray, NDField or C2Array instances. If None, the operands will be seeked in the local and global dictionaries.
out¶ (NDArray or np.ndarray, optional) – The output array where the result will be stored. If not provided, a new array will be created.
where¶ (tuple, list, optional) – A sequence of arguments for the where clause in the expression.
local_dict¶ (dict, optional) – The local dictionary to use when looking for operands in the expression. If not provided, the local dictionary of the caller will be used.
global_dict¶ (dict, optional) – The global dictionary to use when looking for operands in the expression. If not provided, the global dictionary of the caller will be used.
- Returns:
out – A LazyExpr is returned.
- Return type:
Examples
>>> import blosc2 >>> import numpy as np >>> dtype = np.float64 >>> shape = [3, 3] >>> size = shape[0] * shape[1] >>> a = np.linspace(0, 5, num=size, dtype=dtype).reshape(shape) >>> b = np.linspace(0, 5, num=size, dtype=dtype).reshape(shape) >>> a1 = blosc2.asarray(a) >>> a1[:] [[0. 0.625 1.25 ] [1.875 2.5 3.125] [3.75 4.375 5. ]] >>> b1 = blosc2.asarray(b) >>> expr = 'a1 * b1 + 2' >>> operands = { 'a': a1, 'b': b1 } >>> lazy_expr = blosc2.lazyexpr(expr, operands=operands) >>> f"Lazy expression created: {lazy_expr}" Lazy expression created: a1 * b1 + 2 >>> lazy_expr[:] [[ 2. 2.390625 3.5625 ] [ 5.515625 8.25 11.765625] [16.0625 21.140625 27. ]]