blosc2.lazyexpr#
- blosc2.lazyexpr(expression: str | bytes | LazyExpr, operands: dict = None, out: NDArray | ndarray = None, where: tuple | list = 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.
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 with the where arguments. This is useful when the expression contains a where clause. The where arguments should be provided as a sequence.
- 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. ]]