Indexing Functions and Utilities¶
The following functions are useful for performing indexing and oter associated operations.
|
Broadcast an array to a new shape. |
|
Return number of nonzero values along axes. |
|
Expand the shape of an array by adding new axes at the specified positions. |
|
Return the indices of a sorted array following the specified order. |
|
Returns coordinate matrices from coordinate vectors. |
|
Return a sorted array following the specified order. |
|
Remove single-dimensional entries from the shape of the array. |
|
Returns elements of an array along an axis. |
|
Returns elements of an array along an axis. |
- blosc2.broadcast_to(arr, shape)[source]¶
Broadcast an array to a new shape. Warning: Computes a lazyexpr, so probably a bit suboptimal
- blosc2.count_nonzero(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, axis: int | Sequence[int] | None = None) int [source]¶
Return number of nonzero values along axes.
- Parameters:
- Returns:
out – Number of nonzero elements.
- Return type:
int
References
- blosc2.expand_dims(array: NDArray, axis=0) NDArray [source]¶
Expand the shape of an array by adding new axes at the specified positions.
- blosc2.indices(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) NDArray [source]¶
Return the indices of a sorted array following the specified order.
This is only valid for 1-dim structured arrays.
- Parameters:
order¶ (str, list of str, optional) – Specifies which fields to compare first, second, etc. A single field can be specified as a string. Not all fields need to be specified, only the ones by which the array is to be sorted. If None, the array is not sorted.
kwargs¶ (Any, optional) – Keyword arguments that are supported by the
empty()
constructor.
- Returns:
out – The sorted array.
- Return type:
- blosc2.meshgrid(*arrays: NDArray, indexing: str = 'xy') Sequence[NDArray] [source]¶
Returns coordinate matrices from coordinate vectors.
- Parameters:
arrays¶ (NDArray) – An arbitrary number of one-dimensional arrays representing grid coordinates. Each array should have the same numeric data type.
indexing¶ (str) – Cartesian ‘xy’ or matrix ‘ij’ indexing of output. If provided zero or one one-dimensional vector(s) the indexing keyword is ignored. Default: ‘xy’.
- Returns:
out – List of N arrays, where N is the number of provided one-dimensional input arrays, with same dtype. For N one-dimensional arrays having lengths Ni = len(xi),
if matrix indexing ij, then each returned array has shape (N1, N2, N3, …, Nn).
if Cartesian indexing xy, then each returned array has shape (N2, N1, N3, …, Nn).
- Return type:
(List[NDArray])
- blosc2.sort(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) NDArray [source]¶
Return a sorted array following the specified order.
This is only valid for 1-dim structured arrays.
- Parameters:
order¶ (str, list of str, optional) – Specifies which fields to compare first, second, etc. A single field can be specified as a string. Not all fields need to be specified, only the ones by which the array is to be sorted.
kwargs¶ (Any, optional) – Keyword arguments that are supported by the
empty()
constructor.
- Returns:
out – The sorted array.
- Return type:
- blosc2.squeeze(x: NDArray, axis: int | None = None) NDArray [source]¶
Remove single-dimensional entries from the shape of the array.
This method modifies the array in-place. If mask is None removes any dimensions with size 1. If axis is provided, it should be an int or tuple of ints and the corresponding dimensions (of size 1) will be removed.
- Returns:
out
- Return type:
Examples
>>> import blosc2 >>> shape = [1, 23, 1, 11, 1] >>> # Create an array >>> b = blosc2.full(shape, 2**30) >>> b.shape (1, 23, 1, 11, 1) >>> # Squeeze the array >>> blosc2.squeeze(b) >>> b.shape (23, 11)
- blosc2.take(x: NDArray, indices: NDArray[int] | np.ndarray[int], axis: int | None = None) NDArray [source]¶
Returns elements of an array along an axis.
- Parameters:
x¶ (NDArray) – Input array. Should have one or more dimensions (axes).
indices¶ (array-like) – Array indices. The array must be one-dimensional and have an integer data type.
axis¶ (int | None) – Axis over which to select values. If x is a one-dimensional array, providing an axis is optional; however, if x has more than one dimension, providing an axis is required. Default: None.
- Returns:
out – Selected indices of x.
- Return type: