numpy.unravel_index#
- numpy.unravel_index(indices, shape, order='C')#
将扁平索引或扁平索引数组转换为坐标数组的元组。
- 参数:
- indicesarray_like
一个整数数组,其元素是具有
shape维度的数组的扁平化版本的索引。在 1.6.0 版本之前,此函数仅接受一个索引值。- shape整数元组
用于解开
indices的数组的形状。- order{‘C’, ‘F’}, optional
确定索引应以行主序 (C 样式) 或列主序 (Fortran 样式) 进行索引。
- 返回:
- unraveled_coordsndarray 的元组
元组中的每个数组与
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)