brainevent.csr_to_coo_index#
- brainevent.csr_to_coo_index(indptr, indices)[source]#
Convert CSR format index arrays to COO format index arrays.
Transforms the Compressed Sparse Row representation of a sparse matrix (given by
indptrandindices) into the Coordinate representation, which uses explicit row and column index arrays for each non-zero element.- Parameters:
indptr (
Array|ndarray) – Row pointer array in CSR format. For a matrix withmrows, this has lengthm + 1. Elementindptr[i]gives the index intoindiceswhere rowistarts, andindptr[i+1] - indptr[i]is the number of non-zero entries in rowi.indices (
Array|ndarray) – Column index array in CSR format. Contains the column index for each non-zero element. Length equals the number of stored elements.
- Returns:
pre_ids (jax.Array or numpy.ndarray) – Row indices in COO format, with the same length as
indices.post_ids (jax.Array or numpy.ndarray) – Column indices in COO format (identical to the input
indices).
See also
coo_to_csc_indexConvert COO indices to CSC format.
csr_to_csc_indexConvert CSR indices directly to CSC format.
Notes
The function automatically selects NumPy or JAX operations based on the type of the input arrays. When JAX arrays are provided, the computation is wrapped in
jax.ensure_compile_time_eval()so that it runs at trace time.Examples
>>> import numpy as np >>> from brainevent._misc import csr_to_coo_index >>> indptr = np.array([0, 2, 3, 5]) >>> indices = np.array([0, 2, 1, 0, 3]) >>> row_ids, col_ids = csr_to_coo_index(indptr, indices) >>> print(row_ids) [0 0 1 2 2] >>> print(col_ids) [0 2 1 0 3]