[coding] row major vs. column major

numpy 默认 row major c order , PyTorch 默认也是。因为C / C++ 是 row major 添加图片注释,不超过 140 字(可选) 那么 unravel index row = index // cols col = index % cols 假如 import numpy as np np.unravel index

numpy 默认 row major (c-order), PyTorch 默认也是。因为C / C++ 是 row-major

添加图片注释,不超过 140 字(可选)

那么 unravel_index

row = index // cols
col = index % cols

假如

import numpy as np
np.unravel_index([22, 41, 37], (7,6))

在一个 shape 为 7x6 的 array ,flatten 后的22,41,37 ,对应的是array 里的哪三个

输出是一个 tuple of arrays

(array([3, 6, 6]), array([4, 5, 1]))

添加图片注释,不超过 140 字(可选)

第一个 array 代表的是 row number,第二个 array 代表 column number