Lazy Functions

The next functions can be used for computing with any of NDArray, C2Array, NDField and LazyExpr.

Their result is always a LazyExpr instance, which can be evaluated (with compute or __getitem__) to get the actual values of the computation.

abs(ndarr, /)

Calculate the absolute value element-wise.

arcsin(ndarr, /)

Compute the inverse sine, element-wise.

arccos(ndarr, /)

Compute the inverse cosine, element-wise.

arctan(ndarr, /)

Compute the inverse tangent, element-wise.

arctan2(ndarr1, ndarr2, /)

Compute the element-wise arc tangent of ndarr1 / ndarr2 choosing the quadrant correctly.

arcsinh(ndarr, /)

Compute the inverse hyperbolic sine, element-wise.

arccosh(ndarr, /)

Compute the inverse hyperbolic cosine, element-wise.

arctanh(ndarr, /)

Compute the inverse hyperbolic tangent, element-wise.

sin(ndarr, /)

Compute the trigonometric sine, element-wise.

cos(ndarr, /)

Trigonometric cosine, element-wise.

tan(ndarr, /)

Compute the trigonometric tangent, element-wise.

sinh(ndarr, /)

Hyperbolic sine, element-wise.

cosh(ndarr, /)

Compute the hyperbolic cosine, element-wise.

tanh(ndarr, /)

Compute the hyperbolic tangent, element-wise.

exp(ndarr, /)

Calculate the exponential of all elements in the input array.

expm1(ndarr, /)

Calculate exp(ndarr) - 1 for all elements in the array.

log(ndarr, /)

Compute the natural logarithm, element-wise.

log10(ndarr, /)

Return the base 10 logarithm of the input array, element-wise.

log1p(ndarr, /)

Return the natural logarithm of one plus the input array, element-wise.

sqrt(ndarr, /)

Return the non-negative square-root of an array, element-wise.

conj(ndarr, /)

Return the complex conjugate, element-wise.

real(ndarr, /)

Return the real part of the complex array, element-wise.

imag(ndarr, /)

Return the imaginary part of the complex array, element-wise.

contains(ndarr, value, /)

Check if the array contains a specified value.

where(condition[, x, y])

Return elements chosen from x or y depending on condition.

blosc2.abs(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Calculate the absolute value element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression that can be evaluated to get the absolute values.

Return type:

LazyExpr

References

np.abs

Examples

>>> import numpy as np
>>> import blosc2
>>> values = np.array([-5, -3, 0, 2, 4])
>>> ndarray = blosc2.asarray(values)
>>> result_ = blosc2.abs(ndarray)
>>> result = result_[:]
>>> print("Original values:", values)
Original values: [-5 -3  0  2  4]
>>> print("Absolute values:", result)
Absolute values: [5. 3. 0. 2. 4.]
blosc2.arccos(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Compute the inverse cosine, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the inverse cosine of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.arccos

Examples

>>> import numpy as np
>>> import blosc2
>>> numbers = np.array([-1, -0.5, 0, 0.5, 1])
>>> ndarray = blosc2.asarray(numbers)
>>> result_lazy = blosc2.arccos(ndarray)
>>> result = result_lazy[:]
>>> print("Original numbers:", numbers)
Original numbers: [-1.  -0.5  0.   0.5  1. ]
>>> print("Arccos:", result)
Arccos: [3.14159265 2.0943951  1.57079633 1.04719755 0.        ]
blosc2.arccosh(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Compute the inverse hyperbolic cosine, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the inverse hyperbolic cosine of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.arccosh

Examples

>>> import numpy as np
>>> import blosc2
>>> values = np.array([1, 2, 3, 4, 5])
>>> ndarray = blosc2.asarray(values)
>>> result_lazy = blosc2.arccosh(ndarray)
>>> result = result_lazy[:]
>>> print("Original values:", values)
Original values: [1 2 3 4 5]
>>> print("Arccosh:", result)
Arccosh: [0.         1.3169579  1.76274717 2.06343707 2.29243167]
blosc2.arcsin(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Compute the inverse sine, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the inverse sine of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.arcsin

Examples

>>> import numpy as np
>>> import blosc2
>>> numbers = np.array([-1, -0.5, 0, 0.5, 1])
>>> ndarray = blosc2.asarray(numbers)
>>> result_lazy = blosc2.arcsin(ndarray)
>>> result = result_lazy[:]
>>> print("Original numbers:", numbers)
Original numbers: [-1.  -0.5  0.   0.5  1. ]
>>> print("Arcsin:", result)
Arcsin: [-1.57079633 -0.52359878  0.          0.52359878  1.57079633]
blosc2.arcsinh(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Compute the inverse hyperbolic sine, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the inverse hyperbolic sine of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.arcsinh

Examples

>>> import numpy as np
>>> import blosc2
>>> values = np.array([-2, -1, 0, 1, 2])
>>> ndarray = blosc2.asarray(values)
>>> result_lazy = blosc2.arcsinh(ndarray)
>>> result = result_lazy[:]
>>> print("Original values:", values)
Original values: [-2 -1  0  1  2]
>>> print("Arcsinh:", result)
Arcsinh: [-1.44363548 -0.88137359  0.          0.88137359  1.44363548]
blosc2.arctan(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Compute the inverse tangent, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the inverse tangent of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.arctan

Examples

>>> import numpy as np
>>> import blosc2
>>> numbers = np.array([-1, -0.5, 0, 0.5, 1])
>>> ndarray = blosc2.asarray(numbers)
>>> result_lazy = blosc2.arctan(ndarray)
>>> result = result_lazy[:]
>>> print("Original numbers:", numbers)
Original numbers: [-1.  -0.5  0.   0.5  1. ]
>>> print("Arctan:", result)
Arctan: [-0.78539816 -0.46364761  0.          0.46364761  0.78539816]
blosc2.arctan2(ndarr1: NDArray | NDField | C2Array, ndarr2: NDArray | NDField | C2Array, /) LazyExpr[source]

Compute the element-wise arc tangent of ndarr1 / ndarr2 choosing the quadrant correctly.

Parameters:
Returns:

out – A lazy expression representing the element-wise arc tangent of ndarr1 / ndarr2. The result can be evaluated.

Return type:

LazyExpr

References

np.arctan2

Examples

>>> import numpy as np
>>> import blosc2
>>> y = np.array([0, 1, 0, -1, 1])
>>> x = np.array([1, 1, -1, -1, 0])
>>> ndarray_y = blosc2.asarray(y)
>>> ndarray_x = blosc2.asarray(x)
>>> result_lazy = blosc2.arctan2(ndarray_y, ndarray_x)
>>> result = result_lazy[:]
>>> print("y:", y)
y: [ 0  1  0 -1  1]
>>> print("x:", x)
x: [ 1  1 -1 -1  0]
>>> print("Arctan2(y, x):", result)
Arctan2(y, x): [ 0.          0.78539816  3.14159265 -2.35619449  1.57079633]
blosc2.arctanh(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Compute the inverse hyperbolic tangent, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the inverse hyperbolic tangent of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.arctanh

Examples

>>> import numpy as np
>>> import blosc2
>>> values = np.array([-0.9, -0.5, 0, 0.5, 0.9])
>>> ndarray = blosc2.asarray(values)
>>> result_lazy = blosc2.arctanh(ndarray)
>>> result = result_lazy[:]
>>> print("Original values:", values)
Original values: [-0.9 -0.5  0.   0.5  0.9]
>>> print("Arctanh:", result)
Arctanh: [-1.47221949 -0.54930614  0.          0.54930614  1.47221949]
blosc2.conj(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Return the complex conjugate, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the complex conjugate of the input array.

Return type:

LazyExpr

References

np.conj

Examples

>>> import numpy as np
>>> import blosc2
>>> values = np.array([1+2j, 3-4j, -5+6j, 7-8j])
>>> ndarray = blosc2.asarray(values)
>>> result_ = blosc2.conj(ndarray)
>>> result = result_[:]
>>> print("Original values:", values)
Original values: [ 1.+2.j  3.-4.j -5.+6.j  7.-8.j]
>>> print("Complex conjugates:", result)
Complex conjugates: [ 1.-2.j  3.+4.j -5.-6.j  7.+8.j]
blosc2.contains(ndarr: NDArray | NDField | C2Array, value: str | bytes | NDArray | NDField | C2Array, /) LazyExpr[source]

Check if the array contains a specified value.

Parameters:
Returns:

out – A lazy expression that can be evaluated to check if the value is contained in the array.

Return type:

LazyExpr

Examples

>>> import numpy as np
>>> import blosc2
>>> values = np.array([b"apple", b"xxbananaxxx", b"cherry", b"date"])
>>> text_values = blosc2.asarray(values)
>>> value_to_check = b"banana"
>>> expr = blosc2.contains(text_values, value_to_check)
>>> result = expr.compute()
>>> print("Contains 'banana':", result[:])
Contains 'banana': [False  True False False]
blosc2.cos(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Trigonometric cosine, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array containing angles in radians.

Returns:

out – A lazy expression representing the cosine of the input angles. The result can be evaluated.

Return type:

LazyExpr

References

np.cos

Examples

>>> import numpy as np
>>> import blosc2
>>> angles = np.array([0, np.pi/6, np.pi/4, np.pi/2, np.pi])
>>> nd_array = blosc2.asarray(angles)
>>> result_ = blosc2.cos(nd_array)
>>> result = result_[:]
>>> print("Angles in radians:", angles)
Angles in radians: [0.         0.52359878 0.78539816 1.57079633 3.14159265]
>>> print("Cosine of the angles:", result)
Cosine of the angles: [ 1.00000000e+00  8.66025404e-01  7.07106781e-01  6.12323400e-17
-1.00000000e+00]
blosc2.cosh(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Compute the hyperbolic cosine, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the hyperbolic cosine of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.cosh

Examples

>>> import numpy as np
>>> import blosc2
>>> numbers = np.array([-2, -1, 0, 1, 2])
>>> ndarray = blosc2.asarray(numbers)
>>> result_lazy = blosc2.cosh(ndarray)
>>> result = result_lazy[:]
>>> print("Original numbers:", numbers)
Original numbers: [-2 -1  0  1  2]
>>> print("Hyperbolic cosine:", result)
Hyperbolic cosine: [3.76219569 1.54308063 1.         1.54308063 3.76219569]
blosc2.exp(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Calculate the exponential of all elements in the input array.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the exponential of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.exp

Examples

>>> import numpy as np
>>> import blosc2
>>> values = np.array([0, 1, 2, 3, 4])
>>> ndarray = blosc2.asarray(values)
>>> result_lazy = blosc2.exp(ndarray)
>>> result = result_lazy[:]
>>> print("Original values:", values)
Original values: [0 1 2 3 4]
>>> print("Exponential:", result)
Exponential: [ 1.          2.71828183  7.3890561  20.08553692 54.59815003]
blosc2.expm1(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Calculate exp(ndarr) - 1 for all elements in the array.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing exp(ndarr) - 1 of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.expm1

Examples

>>> import numpy as np
>>> import blosc2
>>> values = np.array([-1, -0.5, 0, 0.5, 1])
>>> ndarray = blosc2.asarray(values)
>>> result_lazy = blosc2.expm1(ndarray)
>>> result = result_lazy[:]
>>> print("Original values:", values)
Original values: [-1.  -0.5  0.   0.5  1. ]
>>> print("Expm1:", result)
Expm1: [-0.63212056 -0.39346934  0.          0.64872127  1.71828183]
blosc2.imag(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Return the imaginary part of the complex array, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the imaginary part of the input array.

Return type:

LazyExpr

References

np.imag

Examples

>>> import numpy as np
>>> import blosc2
>>> complex_values = np.array([2+3j, -1+4j, 0-2j, 5+6j])
>>> ndarray = blosc2.asarray(complex_values)
>>> result_ = blosc2.imag(ndarray)
>>> result = result_[:]
>>> print("Original complex values:", complex_values)
Original complex values: [ 2.+3.j -1.+4.j  0.-2.j  5.+6.j]
>>> print("Imaginary parts:", result)
Imaginary parts: [ 3.  4. -2.  6.]
blosc2.log(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Compute the natural logarithm, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the natural logarithm of the input array

Return type:

LazyExpr

References

np.log

Examples

>>> import numpy as np
>>> import blosc2
>>> values = np.array([1, 2, 3, 4, 5])
>>> ndarray = blosc2.asarray(values)
>>> result_lazy = blosc2.log(ndarray)
>>> result = result_lazy[:]
>>> print("Original values:", values)
Original values: [1 2 3 4 5]
>>> print("Logarithm (base e):", result)
Logarithm (base e): [0.         0.69314718 1.09861229 1.38629436 1.60943791]
blosc2.log10(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Return the base 10 logarithm of the input array, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the base 10 logarithm of the input array.

Return type:

LazyExpr

References

np.log10

Examples

>>> import numpy as np
>>> import blosc2
>>> values = np.array([1, 10, 100, 1000, 10000])
>>> ndarray = blosc2.asarray(values)
>>> result_lazy = blosc2.log10(ndarray)
>>> result = result_lazy[:]
>>> print("Original values:", values)
Original values: [    1    10   100  1000 10000]
>>> print("Logarithm (base 10):", result)
Logarithm (base 10): [0. 1. 2. 3. 4.]
blosc2.log1p(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Return the natural logarithm of one plus the input array, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the natural logarithm of one plus the input array.

Return type:

LazyExpr

References

np.log1p

Examples

>>> import numpy as np
>>> import blosc2
>>> values = np.array([-0.9, -0.5, 0, 0.5, 0.9])
>>> ndarray = blosc2.asarray(values)
>>> result_lazy = blosc2.log1p(ndarray)
>>> result = result_lazy[:]
>>> print("Original values:", values)
Original values: [-0.9 -0.5  0.   0.5  0.9]
>>> print("Log1p (log(1 + x)):", result)
Log1p (log(1 + x)): [-2.30258509 -0.69314718  0.          0.40546511  0.64185389]
blosc2.real(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Return the real part of the complex array, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the real part of the input array.

Return type:

LazyExpr

References

np.real

Examples

>>> import numpy as np
>>> import blosc2
>>> complex_values = np.array([1+2j, 3-4j, -5+6j, 7-8j])
>>> ndarray = blosc2.asarray(complex_values)
>>> result_ = blosc2.real(ndarray)
>>> result = result_[:]
>>> print("Original complex values:", complex_values)
Original values: [ 1.+2.j  3.-4.j -5.+6.j  7.-8.j]
>>> print("Real parts:", result)
Real parts: [ 1.  3. -5.  7.]
blosc2.sin(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Compute the trigonometric sine, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array containing angles in radians.

Returns:

out – A lazy expression representing the sine of the input angles. The result can be evaluated.

Return type:

LazyExpr

References

np.sin

Examples

>>> import numpy as np
>>> import blosc2
>>> angles = np.array([0, np.pi/6, np.pi/4, np.pi/2, np.pi])
>>> nd_array = blosc2.asarray(angles)
>>> result_ = blosc2.sin(nd_array)
>>> result = result_[:]
>>> print("Angles in radians:", angles)
Angles in radians: [0.         0.52359878 0.78539816 1.57079633 3.14159265]
>>> print("Sine of the angles:", result)
Sine of the angles: [0.00000000e+00 5.00000000e-01 7.07106781e-01 1.00000000e+00
1.22464680e-16]
blosc2.sinh(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Hyperbolic sine, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the hyperbolic sine of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.sinh

Examples

>>> import numpy as np
>>> import blosc2
>>> numbers = np.array([-2, -1, 0, 1, 2])
>>> ndarray = blosc2.asarray(numbers)
>>> result_lazy = blosc2.sinh(ndarray)
>>> result = result_lazy[:]
>>> print("Original numbers:", numbers)
Original numbers: [-2 -1  0  1  2]
>>> print("Hyperbolic sine:", result)
Hyperbolic sine: [-3.62686041 -1.17520119  0.          1.17520119  3.62686041]
blosc2.sqrt(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Return the non-negative square-root of an array, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the square root of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.sqrt

Examples

>>> import numpy as np
>>> import blosc2
>>> data = np.array([0, np.pi/6, np.pi/4, np.pi/2, np.pi])
>>> nd_array = blosc2.asarray(data)
>>> result_ = blosc2.sqrt(nd_array)
>>> result = result_[:]
>>> print("Original numbers:", data)
Original numbers: [ 0  1  4  9 16 25]
>>> print("Square roots:", result)
Square roots: [0. 1. 2. 3. 4. 5.]
blosc2.tan(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Compute the trigonometric tangent, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array containing angles in radians.

Returns:

out – A lazy expression representing the tangent of the input angles. The result can be evaluated.

Return type:

LazyExpr

References

np.tan

Examples

>>> import numpy as np
>>> import blosc2
>>> angles = np.array([0, np.pi/6, np.pi/4, np.pi/2, np.pi])
>>> nd_array = blosc2.asarray(angles)
>>> result_ = blosc2.tan(nd_array)
>>> result = result_[:]
>>> print("Angles in radians:", angles)
Angles in radians: [0.         0.52359878 0.78539816 1.57079633 3.14159265]
>>> print("Tangent of the angles:", result)
Tangent of the angles: [ 0.00000000e+00  5.77350269e-01  1.00000000e+00  1.63312394e+16
-1.22464680e-16]
blosc2.tanh(ndarr: NDArray | NDField | C2Array | LazyExpr, /) LazyExpr[source]

Compute the hyperbolic tangent, element-wise.

Parameters:

ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array.

Returns:

out – A lazy expression representing the hyperbolic tangent of the input array. The result can be evaluated.

Return type:

LazyExpr

References

np.tanh

Examples

>>> import numpy as np
>>> import blosc2
>>> numbers = np.array([-2, -1, 0, 1, 2])
>>> ndarray = blosc2.asarray(numbers)
>>> result_lazy = blosc2.tanh(ndarray)
>>> result = result_lazy[:]
>>> print("Original numbers:", numbers)
Original numbers: [-2 -1  0  1  2]
>>> print("Hyperbolic tangent:", result)
Hyperbolic tangent: [-0.96402758 -0.76159416  0.          0.76159416  0.96402758]
blosc2.where(condition: LazyExpr, x: NDArray | NDField | ndarray | int | float | complex | bool | str | bytes | None = None, y: NDArray | NDField | ndarray | int | float | complex | bool | str | bytes | None = None) LazyExpr[source]

Return elements chosen from x or y depending on condition.

Parameters:
  • condition (LazyExpr) – Where True, yield x, otherwise yield y.

  • x (NDArray or NDField or np.ndarray or scalar or bytes) – Values from which to choose when condition is True.

  • y (NDArray or NDField or np.ndarray or scalar or bytes) – Values from which to choose when condition is False.

References

np.where