将二维索引转为1维索引 原博客地址:https://blog.csdn.net/qq_42424677/article/details/123011642 将n维索引映射成1维索引 def ravel_index(x, dims): i = 0 for dim, j in zip(dims, x): i *= dim i += j return i