sparse_to_dense_indices#
- lumopt2.utils.sparse_helpers.sparse_to_dense_indices(sparse_indices: ndarray[int64], original_shape: ndarray[int64]) tuple[ndarray, ...]#
Convert flattened sparse indices to multi-dimensional dense indices.
Takes the indices of non-zero entries in a sparse (flattened) representation and converts them back into the corresponding per-axis indices for the original dense array.
- Parameters:
- sparse_indices
np.ndarray[int64] The indices of the non-zero entries in the sparse matrix, in flattened form. 1D array of length N, where N is the number of non-zero entries in the sparse matrix. Assumes 0-based indexing compatible with Python.
- original_shape
np.ndarray[int64] The shape of the original dense matrix before sparsification. 1D array of length M, where M is the number of dimensions.
- sparse_indices
- Returns:
tuple[np.ndarray, …]A tuple of M 1D numpy arrays, where each array contains the indices along a particular axis of the original dense matrix corresponding to the non-zero entries in the sparse matrix. Each numpy array is of length N.