[英]What do we mean by "dimension" when talking about arrays?"
What do we mean by "dimension" when talking about arrays?在谈论数组时,我们所说的“维度”是什么意思?
I understand the idea.我明白这个想法。 But what would be the answer?
但答案会是什么?
For example, int array[5];
例如,
int array[5];
I know that, this is a 1D array.我知道,这是一个一维数组。 It has 1 subscript in the index.
它在索引中有 1 个下标。 But why is it called a 1 Dimensional array?
但是为什么它被称为一维数组呢? Why not 1 Subscript array?
为什么不是 1 个下标数组?
We say "dimension" because that's the general term for this sort of thing. 我们说“维度”因为这是这类事情的总称。 Think about our world, for instance: It has three readily-apparent dimensions (width, height, depth).
想想我们的世界,例如:它有三个容易观察的尺寸(宽度,高度,深度)。 Or think of geometry: A point has zero dimensions, a line has one, a plane has two, a cube has three, etc. The terminology applies to arrays because it precisely describes the same thing in relation to the array.
或者想到几何:一个点有零维度,一个线有一个,一个平面有两个,一个立方体有三个等等。这个术语适用于数组,因为它精确地描述了与数组相关的东西。 The dimensionality of an array is how many axes it has.
数组的维数是它有多少轴。
A one dimensional array has one axis, like a line: 一维数组有一个轴,就像一条线:
XXXXXXXX
You index into it with one subscript, eg array[n]
. 你用一个下标索引它,例如
array[n]
。
A two-dimensional array has two axes, like a plane: 二维数组有两个轴,如平面:
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
You index into it with two subscripts, eg array[x,y]
. 你用两个下标索引它,例如
array[x,y]
。
I won't attempt to represent 3+ dimensional arrays (like cubes) with ASCII art. 我不会尝试使用ASCII艺术来表示3维数组(如立方体)。 :-)
:-)
"Dimension of an Array" is the number of indices, or subscripts, that you need in order to specify an individual element of the array. “数组的维数”是指定数组的单个元素所需的索引或下标数。
Dimensions and subscripts may be confusing. 维度和下标可能会令人困惑。 Subscript is a number (or another type of associative key), while dimension is a description of the range of acceptable keys;
下标是数字(或其他类型的关联键),而维度是可接受键范围的描述; you need one subscript for each dimension of the array.
你需要为数组的每个维度提供一个下标。
For example, in C/C++ a[10][5]
is an array with two dimensions: of size 10 and of size 5. You need two subscripts, or keys, to address its elements. 例如,在C / C ++中
a[10][5]
是一个具有两个维度的数组:大小为10且大小为5.您需要两个下标或键来解决其元素。 One subscript has to be between 0 and 9, inclusive; 一个下标必须在0到9之间,包括0和9; the other subscript is between 0 and 4.
另一个下标介于0和4之间。
The simplest way to think of it is that a dimension of an array is the number of square brackets that follow the type: 最简单的思考方式是数组的维度是类型后面的方括号的数量:
int[] is a single dimension array, int[][] is a 2 dimensional array, etc. int []是单维数组,int [] []是2维数组,等等。
Sometimes it is helpful if you think of an array as if you were graphing them in multiple dimensions. 有时,如果您将数组视为多维绘制它们,则会很有帮助。 A 1-d array is simply a line and has 1 axis in a graph.
1-d阵列只是一条线,在图中有1个轴。 A 2-d array is a table and has two axis if you were to graph it (x,y).
2-d数组是一个表,如果要绘制它(x,y),它有两个轴。 A 3d array is a cube and would have 3 axis (x,y,z).
3d数组是一个立方体,将具有3轴(x,y,z)。
Dimension apply pretty much in the same way to an array as it does not cartesian coordinate system. Dimension以相同的方式应用于数组,因为它不是笛卡尔坐标系。 Dimension means in how many axis an array can grow.
尺寸表示阵列可以生长多少轴。 Example
例
int A[5] is one dimentional, all elements are access by one index
int A[5][5] is two dimentional. Element are aligned along x and y plane.
int A[5][5][5] is three diminutional, elements are aligned in 3D space.
As you grow up 3D, the visual becomes difficult. 随着3D的成长,视觉变得困难。 A 4d Array would be like this
4d阵列就是这样的
int A[5][5][5][5]
that essentially means it can grow in 4 directions. 这实际上意味着它可以在4个方向上生长。 It can be visualized as
它可以被视为
[5][5][5] [5][5][5] [5][5][5] [5][5][5] [5][5][5] [5][5][5]
[5][5][5] [5][5][5] [5][5][5] [5][5][5] [5][5][5] [5][5][5]
[5][5][5] [5][5][5] [5][5][5] [5][5][5] [5][5][5] [5][5][5]
[5][5][5] [5][5][5] [5][5][5] [5][5][5] [5][5][5] [5][5][5]
[5][5][5] [5][5][5] [5][5][5] [5][5][5] [5][5][5] [5][5][5]
which is 5 elements of 3D array A[5][5][5]. 这是3D阵列A [5] [5] [5]的5个元素。 In the above case it is only the 0th element of A[0][5][5][5]
在上面的例子中,它只是A [0] [5] [5] [5]的第0个元素
I had a hard time grasping the idea for different dimensions and how they would pan out.我很难理解不同维度的想法以及它们将如何发展。
So, after reading the response by Sergey and reading the Microsoft doc on arrays I came up with the following script to visualize it:因此,在阅读了Sergey的响应并阅读了有关数组的Microsoft 文档后,我想出了以下脚本来对其进行可视化:
Sub Main()
Worksheets("Sheet1").Range("A1", "AK127").Clear ' Cleaning the array range
For i = 1 To 3
For j = 1 To 4
For k = 1 To 5
Worksheets("Sheet1").Cells(1, ((k - 1) * 5) + 1).Offset((i), (j)).Value = i & "+" & j & "-" & k ' Assigning numbers
Worksheets("Sheet1").Cells(1, ((k - 1) * 5) + 1).Offset((i), (j)).Interior.Color = RGB(255 / j, 155, 150) ' Assigning colors
Next k
Next j
Next i
End Sub
It will spit out 5 blocks (k 1 to 5) of 3 by 4 arrays (i by j) with color schemes.它将使用颜色方案吐出 5 个块(k 1 到 5)的 3 x 4 阵列(i x j)。
I hope this was a helpful visualization.我希望这是一个有用的可视化。 One could play around with the numbers or
i,j,k
parameters to see how they change appearance.可以使用数字或
i,j,k
参数来查看它们如何改变外观。
A multi-dimensional array is one that allows its members to be arrays, too. 多维数组也是允许其成员为数组的数组。 For example :
例如 :
a = [1, 2, 3]; a = [1,2,3]; // single dimension array b = [7, 8, 9];
//单维数组b = [7,8,9]; // single dimension array
//单维数组
c = [a, b]; c = [a,b]; // multidimension (2-dimension) array.
//多维(二维)数组。 An array of arrays.
一组数组。
So now c[0] is assigned the array a as its element, and c[1] is b. 所以现在c [0]被赋予数组a作为其元素,而c [1]是b。 Members of a multidimensional array can be addressed such as:
可以处理多维数组的成员,例如:
c[0][0] (which would be a[0] in this case, or 1... c[1][2] (which would be b[2] in this case, or 9... c [0] [0](在这种情况下为[0],或1 ... c [1] [2](在这种情况下为b [2],或9 ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.