numpy.unravel_index#

numpy.unravel_index(indices, shape, order='C')#

将扁平索引或扁平索引数组转换为坐标数组的元组.

参数:
indicesarray_like

一个整数数组,其元素是维度为 shape 的数组的扁平版本的索引.在1.6.0版本之前,此函数仅接受一个索引值.

shapetuple of ints

用于解开 indices 的数组的形状.

order{‘C’, ‘F’},可选

确定是否应将索引视为按行优先(C风格)或按列优先(Fortran风格)的顺序进行索引.

返回:
展开的坐标ndarray 元组

元组中的每个数组都具有与 indices 数组相同的形状.

示例

>>> import numpy as np
>>> np.unravel_index([22, 41, 37], (7,6))
(array([3, 6, 6]), array([4, 5, 1]))
>>> np.unravel_index([31, 41, 13], (7,6), order='F')
(array([3, 6, 6]), array([4, 5, 1]))
>>> np.unravel_index(1621, (6,7,8,9))
(3, 1, 4, 1)