+ 1

Can anyone please explain to me how two dimensional arrays run?

Two dimensional arrays

20th May 2020, 9:57 AM
Darkseid
Darkseid - avatar
2 Answers
+ 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.
20th May 2020, 10:04 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
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
20th May 2020, 10:07 AM
Slick
Slick - avatar