多维数组的线性模拟 [英] linear simulation of multidimensional array
本文介绍了多维数组的线性模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何使用模拟线性阵列二维数组 [X + Y *宽]
作为一个线性指标。
I know how to simulate a 2d array in a linear array using [x + y * width]
as a linear index.
我可以扩展这3D数组: [X + Y *宽+ Z *宽*高]
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 *宽+ Z *宽*高+ W *宽*高*深+ ...
Sure. Just extending your example gives x + y*width + z*width*height + w*width*height*depth + ...
在换句话说, DIM1 DIM2 + * +尺寸1 *为dim3 *尺寸1 + size2个* dim4 *尺寸1 * size2个+ size3 ...
这篇关于多维数组的线性模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文