brainevent.csc_to_csr_index#
- brainevent.csc_to_csr_index(csc_indptr, csc_indices, *, shape, include_perm=True)[source]#
Convert CSC format index arrays to CSR format.
Inverse companion of
csr_to_csc_index(). A Compressed Sparse Column layout of a matrixWwith shape(n_rows, n_cols)is, array for array, the Compressed Sparse Row layout ofW.Twith shape(n_cols, n_rows). Building the CSR structure ofWtherefore reduces to callingcsr_to_csc_index()on the transposed interpretation.- Parameters:
csc_indptr (
Array|ndarray) – Column pointer array in CSC format. For a matrix withn_colscolumns, this has lengthn_cols + 1.csc_indices (
Array|ndarray) – Row index array in CSC format. Contains the row index for each non-zero element, ordered by column.shape (
Tuple[int,int]) – A(n_rows, n_cols)tuple giving the dimensions of the matrix the CSC arrays describe. Keyword-only argument.include_perm (
bool) – IfTrue(default), return the permutation that maps CSR slots back to CSC data positions. IfFalse, returnNonefor the third result while still constructing the CSR structure.
- Returns:
csr_indptr (jax.Array or numpy.ndarray) – Row pointer array in CSR format. Length
n_rows + 1.csr_indices (jax.Array or numpy.ndarray) – Column index array in CSR format.
perm (jax.Array or numpy.ndarray) – Permutation array reordering data values from CSC order to CSR order. If
datais the CSC data array, thendata[perm]gives the values in CSR order.
- Raises:
AssertionError – If
shapeis not a length-2 tuple/list of positive integers.
See also
csr_to_csc_indexThe forward CSR-to-CSC companion (mutual inverse).
coo_to_csc_indexConvert COO indices to CSC indices.
Notes
Because the two helpers are mutual inverses on the same structure, the permutations they return compose to the identity:
csr_perm[csc_perm] == arange(nse).Examples
>>> import numpy as np >>> from brainevent._misc import csr_to_csc_index, csc_to_csr_index >>> indptr = np.array([0, 2, 3, 5]) >>> indices = np.array([0, 2, 1, 0, 3]) >>> csc_indptr, csc_indices, _ = csr_to_csc_index(indptr, indices, shape=(3, 4)) >>> csr_indptr, csr_indices, _ = csc_to_csr_index( ... csc_indptr, csc_indices, shape=(3, 4) ... )