bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / ravel_multi_index
_ArrayFunctionDispatcher
numpy:ravel_multi_index
Signature
def ravel_multi_index ( multi_index , dims , mode = raise , order = C ) Summary
Converts a tuple of index arrays into an array of flat indices, applying boundary modes to the multi-index.
Parameters
multi_index: tuple of array_likeA tuple of integer arrays, one array for each dimension.
dims: tuple of intsThe shape of array into which the indices from
multi_indexapply.mode: {'raise', 'wrap', 'clip'}, optionalSpecifies how out-of-bounds indices are handled. Can specify either one mode or a tuple of modes, one mode per index.
'raise' -- raise an error (default)
'wrap' -- wrap around
'clip' -- clip to the range
In 'clip' mode, a negative index which would normally wrap will clip to 0 instead.
order: {'C', 'F'}, optionalDetermines whether the multi-index should be viewed as indexing in row-major (C-style) or column-major (Fortran-style) order.
Returns
raveled_indices: ndarrayAn array of indices into the flattened version of an array of dimensions
dims.
Examples
import numpy as np arr = np.array([[3,6,6],[4,5,1]]) np.ravel_multi_index(arr, (7,6)) np.ravel_multi_index(arr, (7,6), order='F') np.ravel_multi_index(arr, (4,6), mode='clip') np.ravel_multi_index(arr, (4,4), mode=('clip','wrap'))✓
np.ravel_multi_index((3,1,4,1), (6,7,8,9))
✗See also
- unravel_index
Aliases
-
numpy.ravel_multi_index