多维数组的线性模拟 [英] linear simulation of multidimensional array
本文介绍了多维数组的线性模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何使用 [x + y * width]
作为线性索引在线性数组中模拟二维数组.
I know how to simulate a 2d array in a linear array using [x + y * width]
as a linear index.
我可以将其扩展到 3d 数组:[x + y * width + z * width * height]
.
I can extend this to 3d arrays: [x + y * width + z * width * height]
.
N维数组有通用公式吗?
Is there a general formula for N-dimensional array?
我正在寻找与语言无关的答案.
I'm looking for a language-agnostic answer.
推荐答案
好的.只是扩展你的例子给 x + y*width + z*width*height + w*width*height*depth + ...
Sure. Just extending your example gives x + y*width + z*width*height + w*width*height*depth + ...
换句话说,dim1 + dim2*size1 + dim3*size1*size2 + dim4*size1*size2*size3 + ...
这篇关于多维数组的线性模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文