Until now, you have worked with one-dimensional arrays, where all the data was stored in a single line or row. Now, let’s see what a multidimensional array is.
A multidimensional array is an array of arrays. For example, a two-dimensional array would be an array with each element as a one-dimensional array.
1-D array : [1, 2, 3, 4, 5] 2-D array : [ [1, 2, 3, 4, 5], [6, 7, 8, 9, 10] ]
Similarly, a three-dimensional array can be thought of as an array with each element as a two-dimensional array. To create multidimensional arrays, you can give a multidimensional list as an input to the np.array function.
Let’s hear from Vaidehi as she explains the concept of two-dimensional arrays.
# [00:28] There is an error in the brackets of 3-D Array. A 3-D array would look like this:
[[[a, b, c], [d, e, f], [g, h, i]],
[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
[[A, B, C], [D, E, F], [G, H, I]]]
In NumPy, the dimension is called axis. In NumPy terminology, for 2-D arrays:
Multidimensional arrays are indexed using as many indices as the number of dimensions or axes. For instance, to index a 2-D array, you need two indices: array[x, y]. Each axis has an index starting at 0. The figure provided above shows the axes and their indices for a 2-D array.
In the next video, you will learn how to subset and operate over multidimensional arrays.
In the next segment, you will learn how to initialise fixed-length one-dimensional NumPy arrays using different functions.