+ 1
Can anyone please explain to me how two dimensional arrays run?
Two dimensional arrays
2 Respuestas
+ 7
One dimensional array: [1, 2, 3, 4]
Two dimensional array:
[[1, 2, 3], [4, 5, 6], [7, 8, 9] ]
If you put it on more lines:
[ [1, 2, 3],
[4, 5, 6],
[7, 8, 9] ]
It is like a matrix. You want number 3? It is located at [0][2]
You want 5? It is at [1][1]
Want 7? Go to [2][0]
Basically, a 2d array is a array that contains more arrays.
0
In python, without getting to fancy using numpy, 2D arrays are just lists within a list. They work basically the same as regular lists but with extra index.
1D array:
n = [1,2,3,4,5,6]
print(n[3])
print(n[::-1])
4
[6,5,4,3,2,1]
========================
2D array:
a = [[1,2,3], [4,5,6]]
print(a[1])
print(a[0][1])
[4,5,6]
2