How do you turn a flat heatmap peak index back into coordinates?
unravel_index converts a linear offset into axis indices using the original shape and traversal order.
numpy.unravel_index in practice
In a row-major two-by-three map, offset four is the second row and second column. If the map was transposed or flattened column first, use those original conventions.
import numpy as np
np.unravel_index(4,(2,3))Result [1, 1]
中文
热图展平后的峰值编号怎样还原成坐标?
unravel_index 结合原始形状与遍历顺序,把一维偏移换算成各轴下标。
numpy.unravel_index 算例
两行三列的图按行展平,编号 4 表示第二行第二列。若图曾转置或按列展开,应使用当时的形状和顺序。
import numpy as np
np.unravel_index(4,(2,3))结果 [1, 1]