Indexing and Manipulation Functions and Utilities¶
The following functions are useful for performing indexing and other associated operations.
|
Broadcast an array to a new shape. |
|
Concatenate a list of arrays along a specified axis. |
|
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. |
|
Stack multiple arrays, creating a new axis. |
|
Returns elements of an array along an axis. |
|
Returns elements of an array along an axis. |
- blosc2.broadcast_to(arr: Array, shape: tuple[int, ...]) NDArray[source]¶
Broadcast an array to a new shape. Warning: Computes a lazyexpr, so probably a bit suboptimal
- Parameters:
arr¶ (blosc2.Array) – The array to broadcast.
shape¶ (tuple) – The shape of the desired array.
- Returns:
broadcast (NDArray)
A new array with the given shape.
- blosc2.concat(arrays: list[NDArray], /, axis=0, **kwargs: Any) NDArray[source]¶
Concatenate a list of arrays along a specified axis.
- Parameters:
- Returns:
out – A new NDArray containing the concatenated data.
- Return type:
Examples
>>> import blosc2 >>> import numpy as np >>> arr1 = blosc2.arange(0, 5, dtype=np.int32) >>> arr2 = blosc2.arange(5, 10, dtype=np.int32) >>> result = blosc2.concat([arr1, arr2]) >>> print(result[:]) [0 1 2 3 4 5 6 7 8 9]
- blosc2.count_nonzero(ndarr: blosc2.Array, 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: Array, 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:
array¶ (blosc2.Array) – The (structured) array to be sorted.
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: blosc2.Array, indexing: str = 'xy') Sequence[NDArray][source]¶
Returns coordinate matrices from coordinate vectors.
- Parameters:
*arrays¶ (blosc2.Array) – 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: Array, 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:
array¶ (blosc2.Array) – The (structured) array to be sorted.
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: Array, axis: int | Sequence[int]) NDArray[source]¶
Remove single-dimensional entries from the shape of the array.
This method modifies the array in-place.
- Parameters:
- Returns:
out – An output array having the same data type and elements as x.
- 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.stack(arrays: list[NDArray], axis=0, **kwargs: Any) NDArray[source]¶
Stack multiple arrays, creating a new axis.
- Parameters:
- Returns:
out – A new NDArray containing the stacked data.
- Return type:
Examples
>>> import blosc2 >>> import numpy as np >>> arr1 = blosc2.arange(0, 6, dtype=np.int32, shape=(2,3)) >>> arr2 = blosc2.arange(6, 12, dtype=np.int32, shape=(2,3)) >>> result = blosc2.stack([arr1, arr2]) >>> print(result.shape) (2, 2, 3)
- blosc2.take(x: Array, indices: Array, axis: int | None = None) NDArray[source]¶
Returns elements of an array along an axis.
- Parameters:
x¶ (blosc2.Array) – 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:
- blosc2.take_along_axis(x: Array, indices: Array, axis: int = -1) NDArray[source]¶
Returns elements of an array along an axis.
- Parameters:
x¶ (blosc2.Array) – Input array. Should have one or more dimensions (axes).
indices¶ (array-like) – Array indices. The array must have same number of dimensions as x and have an integer data type.
axis¶ (int) – Axis over which to select values. Default: -1.
- Returns:
out – Selected indices of x.
- Return type: