Multidimensional arrays

The concept of Multidimensional Array can be explained as a technique of defining and storing the data on a format with more than one dimension. In Python, Multidimensional Array can be implemented by fitting in a list/tuple inside another list/tuple, which is basically a nesting list/tuple.

Remember to use the correct number of square brackets to index out the element you want to take. If you use one pair of square brackets in a 2D list/tuple, you are referring to a whole list/tuple, not a single element. You will need N pairs of square brackets to refer a single element in an N-Dimension array.

Also, keep in mind that you can mix up lists with tuples in the N-Dimensions.

Creating a 2D list/tuple

You can declare the 2D list by hand with

For practical use, it will be better to declare your

Take care of using square brackets enclosing the for loop, because if you use parentheses that will create a generator, I will explain what it is in the next topic. To create a tuple

""" Declared by hand """
A = [[0,0],[1,1],[2,2]]
B = [['Copernicus', 160], ['Einstein', 160], ['Galileo', 185], ['Descartes', 180]]

""" Declared with for loops """
C = [[y for x in range(2)] for y in range(5)]
# B = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]

D = [[(x, x+y) for x in range(3)] for y in range(3)]
# C = [[[0, 0], [1, 1], [2, 2]], [[0, 1], [1, 2], [2, 3]], [[0, 2], [1, 3], [2, 4]]]

E = tuple([tuple([x for x in range(5)]) for y in range(2)])
# D = ((0, 1, 2, 3, 4), (0, 1, 2, 3, 4))

Iterating over a 2D list/tuple

bla bla bla

#code 2

Copy an N-Dimensional array

bla bla bla

#code 3

Problems

Rotate matrix
bla bla 11111
bla bla bl222
bla bla bl322
bla bla bl422