C#/C++:如何可视化多维数组
例如:二维数组可以被可视化为带有方砖的砖墙,其中每块砖代表数组中的一个坐标。 3 维数组可以以同样的方式可视化为盒子或立方体。
但是,这里是棘手的部分,如何可视化具有多个(超过 3 个)维度的数组?或者,对于这一部分,如何可视化不仅具有多个维度,而且具有多个层的多个维度的数组?
例如:如何可视化这样的数组:Array[3,3,3,3][3,3][3,3,3,3,3][3]?
For example: A two-dimensional array can be visualized like a brick-wall with square bricks, where every brick represents a coordinate in our array. A 3-dimensional array can in the same way be visualized as a box, or cube.
But, here is the tricky part, how do you visualize an array with multiple (More than 3) dimensions? Or, for that part, how do you visualize an array with not only multiple dimensions, but multiple dimensions in several layers?
For example: How do you visualize an array such as this: Array[3,3,3,3][3,3][3,3,3,3,3][3]?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
如何可视化数组实际上取决于它们的实际用途。如果您使用数组来表示空间关系,那么您可以从将其想象为立方体中受益,但您也无需想象超过 3 个维度。如果您确实想要实现第四个时间维度,您可以想象您的立方体的内容随着时间的推移而变化。
否则,您可能会跟踪密切相关的记录。也许每个第一级元素是星系,第二级元素是星团,第三级元素是太阳系,第四级元素是行星,第五级元素是大陆......
在这种情况下你可以想象它是数组中的数组。如果你需要一个 4 维数组,那么你可以想象一个立方体,但每个子立方体实际上是一个一维数组。
如果您需要一个 5 维数组,那么您可以想象一个立方体,但每个子立方体都分为您的“砖墙”示例。
6维是一个立方体,每个子立方体都是其自己划分的立方体。
这往往会在 6 维之后崩溃。除此之外,通常还有一个更实际的原因,即您需要如此多的维度。例如,像 eHarmony 这样的网站通过在 20+ 维空间上使用正常几何形状来进行匹配。你有一个维度代表“幽默”,一个维度代表“好看”,一个维度代表“热爱购物”……然后你可以带两个人并应用距离公式(将每个维度差异平方,将这些差异相加,开平方) )并确定两个人的兼容性。因此,如果一个人在我们的 9 维人格矩阵上得分为“5,3,9,2,8,4,7,3,1”,而另一个人得分为“9,3,7,1,8,2,8,4” , 7" 那么您的兼容性是:
这可以应用于无限维度并且仍然有效。然而,由于这些维度不适用于空间,因此无需将它们可视化。相反,在这种特殊情况下,我们实际上可以将其想象为具有多个整数值的一维数组。请注意,我们可以简化这个数组的原因是,我们的多维数组只包含一个“1”,其余的都是“0”(表示这个人在这个数组中的位置)。
远离 eHarmony 的例子,重点是——在一定数量的维度之后,你通常会对数组有一个实际的用途,这有助于一种感知它的方法。
How you visualize the arrays really depends on their practical use. If you are using the arrays for spacial relations then you can benefit from imagining it as a cube, but you also lose the need to imagine more than 3 dimensions. If you really and truly wanted to implement a fourth time dimension, you could just imagine your cube with the contents changing as time progresses.
Otherwise you may be keeping track of strongly related records. Perhaps each of the first elements is a galaxy, the second-level elements are star clusters, the third-level elements are solar systems, the fourth-level elements are planets, the fifth-level elements are continents...
In this case you can imagine it was arrays within arrays. If you need a 4-dimensional array then you can imagine a cube, but each sub-cube is actually a one-dimensional array.
If you need a 5-dimensional array then you can imagine a cube, but each sub-cube is divided into your "brick wall" example.
6-dimensional is a cube with each sub-cube being its own divided cube.
This tends to fall apart at after 6 dimensions. Beyond this there is usually a more practical reason that you need so many dimensions. For example, websites like eHarmony do their match-making by using normal geometry on 20+ -dimensional spaces. You have one dimension for "humor", one for "good looks", one for "love of shopping"... Then you can take two people and apply distance formula (square each of the dimensional differences, add these differences, square root) and determine how compatible the two people are. So if one person scored "5, 3, 9, 2, 8, 4, 7, 3, 1" on our 9-dimensional personality matrix and another scored "9, 3, 7, 1, 8, 2, 8, 4, 7" then your compatibility is:
This can be applied over infinite dimensions and still work. Since these dimensions don't apply to space, however, there's no need to visualize them as such. Instead, in this particular case, we can actually imagine it as just a single-dimensional array with several integer values. The reason we can simplify this array, mind you, is that our multi-dimensional array only contains a single "1" and all of the rest are "0"s (indicating the location of the person in this array).
Moving away from the eHarmony example, the point is- after a certain amount of dimensions you usually have a practical purpose for the array which lends itself to a method of perceiving it.
有些人可以在心里建立 n 维几何模型,其中 n > 1。 3,至少就简单的形状而言,有些不能。 (最近与一位研究高级 n 维几何领域的人交谈时,我感到非常惊讶,得知他无法想象超立方体,而我却发现他的数学远远超出了我的能力)。
但这并不是真的必要。事实上,将二维数组可视化为笛卡尔坐标也很少是特别必要的 - 当您在实践中使用二维数组时,每个轴都有一些目的,并且该目的很快就会变得比任何视觉表示都更重要。
如果确实需要,那么可以考虑将二维数组视为一维结构的有序集合。同样,3 维数组可以被认为是二维结构的有序集合,或一维集合的集合(这些集合大小相等 - 允许不同大小的物质移动到锯齿状数组中)。
因此,4 维数组可以被视为 3 维结构的有序集合,依此类推。
Some people can mentally model n-dimensional geometry for n > 3, at least as far as simple shapes go, and some cannot. (I was quite surprised when recently talking to someone whose field was advanced n-dimensional geometry to learn that he couldn't visualise a hypercube, while I can but find his mathematics quite beyond me).
It isn't really necessary though. Indeed, it's rarely particularly necessary to visualise a two-dimensional array as Cartesian coördinates either - when you are using a 2-dimensional array in practice you have some purpose for each axis, and that purpose quickly becomes more important than any visual representation.
If you do need to, then consider that a 2-dimensional array can also be considered as an ordered set of 1-dimensional structures. Likewise a 3-dimensional array can be considered an ordered set of 2-dimensional structures, or a set of sets of 1-dimensional (with these sets of equal size - allowing different sizes moves matters into jagged arrays).
Hence a 4-dimensional array can be considered an ordered set of 3-dimensional structures, and so on.
你不知道。您很少需要超过 2 或 3 维的情况。如果您需要更多,那么也许额外的维度应该被建模为对象的属性,在这种情况下,您可以将它们视为属性,而不是尝试想象一些神话般的超立方体。
You don't. It's rare that you even need more than 2 or 3 dimensions. If you need more than that, then perhaps the extra dimensions should be modeled as properties on an object instead, in which case you can see them as attributes and not try to imagine some mythical hypercube.
有许多可爱的方法可以可视化多维数据。我最喜欢的之一是 Alfred Inselberg 的 平行坐标,它将每个维度表示为垂直轴,并且每个数据点作为连接它们的线程:
另一个很棒的可视化是 Ramana Rao 的 桌面镜头 (pdf):
这将每个维度表示为一列,就像在电子表格中一样,但以图形方式而不是数字方式表示。它特别擅长展示维度之间的相关性;当您按一维排序时,很容易看到相关维度如何与其一起排序。
There are many lovely ways to visualize multidimensional data. One of my favorites is Alfred Inselberg's Parallel Coordinates, which represents each dimension as a vertical axis, and each data point as a thread connecting them all:
Another great visualization is Ramana Rao's Table Lens (pdf):
This represents each dimension as a column, as in a spreadsheet, but graphically rather than numerically. It is particularly good at showing correlation between dimensions; as you sort by one dimension, it is easy to see how correlated dimensions sort alongside it.
尝试对其进行减法。如果您需要想象一个十维数组,那么首先想象所有有限非负整数 n 的所有 n 维实值欧几里德向量空间的集合。 { R0, R1, R2, ... }
现在想象一下去掉几乎所有这些,只留下 R10。
现在想象一下,去掉几乎所有这些,这样就只剩下 R10 中的整数格点了。
现在想象一下,去掉几乎所有这些,这样你就只有整数晶格点的超矩形子集。
你就完成了;这是 10 维数组的良好可视化。当您将其视为所有可能的 n 维向量空间集合的子集时,它确实非常小。
如果您对高维空间主题感兴趣,您可能想阅读我对有关高维向量空间数据库搜索算法的一些有趣事实的温和介绍:
http://blogs.msdn.com/b/ericlippert/archive/tags/high+Dimension+spaces/
Try being subtractive about it. If you need to imagine, say, a ten dimensional array then start by imagining the set of all n-dimensional real-valued Euclidean vector spaces for all finite non-negative integers n. { R0, R1, R2, ... }
Now imagine taking away almost all of that, leaving just R10.
Now imagine taking away almost all of that, so that you have just the integer lattice points in R10 left.
Now imagine taking away almost all of that, so that you have just a hyper-rectangular subset of the integer lattice points.
And you're done; that's a good visualization of a 10-dimensional array. It's really very small when you think about it as a subset of the set of all possible n-dimensional vector spaces.
If the subject of high-dimensional spaces interests you, you might want to read my gentle introduction to some interesting facts about search algorithms on high-dimensional vector space databases:
http://blogs.msdn.com/b/ericlippert/archive/tags/high+dimensional+spaces/
对于 3 个维度,您唯一的选择是树视图或向下钻取。
Over 3 dimensions, your only options are either a tree view or a drill-down.
与可视化 4 个空间维度的方式相同:“切片”、叠加或将其投影到您想要的内容上已经理解并可以想象。
The same way you visualize 4 spatial dimensions: "slice", superimpose, or project it onto what you already understand and can visualize.
将每个额外的维度视为一个“封闭的盒子”。将 2D 数组视为 1D 数组的数组,将 3D 数组视为 2D 数组的数组,依此类推。
以下是一些示例...
1D 1x2 数组:
2D 2x2 数组:
3D 2x2x2 数组:
Think of every extra dimension as an "enclosing box". Think of a 2D array as an array of 1D arrays, of a 3D array as an array of 2D arrays, and so on.
Here are some examples...
1D 1x2 array:
2D 2x2 array:
3D 2x2x2 array:
您可以将财务报告可视化为一个数组,其中数据以电子表格形式来自多个实体:
然后,出于全球整合的目的,控制者可能会收到来自每个区域的工作簿 - 这将是第四个维度。如果您需要随着时间的推移操纵销售数据(例如发现趋势),第五个维度可能是“时间”。
理论上,您可以在单个 5D 数组变量中保存多年、多区域销售数据。
正如人们上面所说,您确实需要首先考虑一个应用程序,然后逻辑数据结构将有助于定义合适的物理形式。任何可以进行关系建模的属性集通常都可以放置在数组中。
托尼
You could visualise a financial report as an array where data is coming in from multiple entities in spreadsheet form:
Then, for purposes of global consolidation, a Controller may receive a workbook from each Region - this would be the 4th dimension. A fifth dimension could be "time" if you have a need to manipulate sales data over time (to spot trends for instance).
In theory, you could hold multi-year, multi-region sales data in a single 5D array variable.
As people have said above, you really need to have an application in mind first and then the logical data structure will help define a suitable physical form. Any set of attributes that can be modelled relationally can be placed in an array normally.
tony
将 4D 数组可视化为 1D 立方体数组。 5D 数组作为 2D 立方体数组。 6D 数组作为立方体的 3D 数组,或立方体的立方体。 7D 数组作为立方体的立方体的 1D 数组,等等......
Visualize a 4D array as a 1D array of cubes. A 5D array as a 2D array of cubes. And a 6D array as a 3D array of cubes, or a cube of cubes. A 7D array as a 1D array of cubes of cubes, etc...
忽略是否需要这些维度,为什么不将 4D 数组设想为“立方体”的 1D 数组(线)。 (即:一个 1D 数组,其中每个元素都指向一个 3D 立方体)。这可以根据需要放大(即:每个元素都指向一个立方体的 2D 表面)。这当然不是超立方体的“外观”,但这不是必需的。
Ignoring whether these dimensions are neeeded, why not just envision a 4D array as a 1D array (line) of "cubes". (ie: an 1D array where each element points to a 3D cube). This can be scaled up as needed (ie: 2D surface where each element points to a cube). This of course isn't how a hypercube would 'look', but that isn't required.
3 维数据的选项卡
为您提供 4 个维度,选项卡的选项卡为您提供 n 维。
这不一定是可视化它的最佳方式。也不适合在任何维度上旋转。
但是,这取决于您想要可视化的内容,
例如可以将 RGB 转换为 2D 贴图,然后投影到立方体上,为您提供 4d 信息
tabs :)
tabs of 3 dimensional data gives you 4 dimensions, tabs of tabs gives you n dimensional.
not thats necessarily the best way to visualize it. Also not good for rotating in any of the dimensions.
but then, it depends what you are trying to visualise
RGB for instance can be turned into a 2D map and then projected onto a cube, giving you 4d information
不想在这里放弃农场,但这是我如何看待 PHP 中的多维数组的一个例子。
$map[room][x][y][z][id][photopath][flag1][flag2]
我想象它作为 3D 空间中的一个点会是什么样子,然后我只需添加排序属性。在这里,假设您正在玩《毁灭战士 3》。每张地图都可分为多个房间,每个房间都有带有 x、y 和 z 坐标的像素。每个点都可以有一个与之关联的对象 ID(怪物、物品等)。我为我的应用程序添加了更多属性,但基本上就是这样。数组中的点不一定必须是几何精确的;它可以有任何意义。我不知道这是否与其他人的做法相似。我确实知道使用 gd 图形库可以为动态多维数组提供一个很好的可视化工具,但上次我为这个客户工作时没有参与该项目。
Not looking to give away the farm here, but this is an example of how I look at multidimensional arrays in PHP.
$map[room][x][y][z][id][photopath][flag1][flag2]
I imagine what it would look like as a point in 3D space, then I just add sorting attributes. Here, imagine you're playing Doom 3. Each map is divisible into rooms, which have pixels with x, y, and z coordinates. Each of those points can have an object id (monster, item, etc.) associated with it. I've added more attributes for my application, but this is basically it. A point in the array doesn't necessarily have to be geometrically accurate; it can have any meaning. Whether this is similar to what other people do, I don't know. I do know that using the gd graphics library would make a nice visualizer for multidimensional arrays on the fly, but I didn't get to that project last time I was working for this client.