Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
3-D Arrays | Dimensions in Arrays
NumPy in a Nutshell
course content

Course Content

NumPy in a Nutshell

NumPy in a Nutshell

1. Getting Started with NumPy
2. Dimensions in Arrays
3. Indexing and Slicing
4. Important Functions

book3-D Arrays

With three-dimensional arrays, everything is quite clear and logical. These arrays consist of elements that are two-dimensional arrays.

Let's practice to make it easier to understand.

Here's an example of how we can create a 3-D array with four 2-D arrays, each containing three 1D arrays with 2 elements:

123456789101112131415161718
import numpy as np # Creating array arr = np.array([ [ [1, 2], [4, 3], [7, 4] ], [ [2, 10], [9, 15], [7, 5] ], [ [1, 11], [3, 20], [0, 2] ], [ [9, 25], [6, 13], [9, 8] ] ]) # Displaying array print(arr)
copy

Let's now take a look at the visualization of this array:

Our 3D array is 4x3x2, hence why we have a rectangular parallelepiped with sides equal to 4, 3 and 2, respectively. The innermost 1D arrays lie along the axis 2 (e.g., [1, 2] or [4, 3]) where each small cube with side equal to 1 is a particular element (number).

Basically, all the elements of a 3D array are stored inside these innermost 1D arrays. The rectangular parallelepiped is just a visual representation for us to make things clear. The total number of elements (small cubes) is equal to 24 (the volume of the rectangular parallelepiped), which 4 * 3 * 2.

Note

Since its a 2D visualization of a 3D object, we cannot display and see here all the elements.

Time to test your strength!

Task

  1. You need to create two arrays:
    • the first one is a 2-D array containing two arrays with the values: 1, 5, 2 and 34, 2, 7;
    • the second one is a 3-D array (use only a single line to create this array) containing two 2-D arrays, both of which include two arrays with the values 5, 3, 8 and 6, 1, 9.
  2. Display these arrays on the screen: first arr_1, then arr_2.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 4
toggle bottom row

book3-D Arrays

With three-dimensional arrays, everything is quite clear and logical. These arrays consist of elements that are two-dimensional arrays.

Let's practice to make it easier to understand.

Here's an example of how we can create a 3-D array with four 2-D arrays, each containing three 1D arrays with 2 elements:

123456789101112131415161718
import numpy as np # Creating array arr = np.array([ [ [1, 2], [4, 3], [7, 4] ], [ [2, 10], [9, 15], [7, 5] ], [ [1, 11], [3, 20], [0, 2] ], [ [9, 25], [6, 13], [9, 8] ] ]) # Displaying array print(arr)
copy

Let's now take a look at the visualization of this array:

Our 3D array is 4x3x2, hence why we have a rectangular parallelepiped with sides equal to 4, 3 and 2, respectively. The innermost 1D arrays lie along the axis 2 (e.g., [1, 2] or [4, 3]) where each small cube with side equal to 1 is a particular element (number).

Basically, all the elements of a 3D array are stored inside these innermost 1D arrays. The rectangular parallelepiped is just a visual representation for us to make things clear. The total number of elements (small cubes) is equal to 24 (the volume of the rectangular parallelepiped), which 4 * 3 * 2.

Note

Since its a 2D visualization of a 3D object, we cannot display and see here all the elements.

Time to test your strength!

Task

  1. You need to create two arrays:
    • the first one is a 2-D array containing two arrays with the values: 1, 5, 2 and 34, 2, 7;
    • the second one is a 3-D array (use only a single line to create this array) containing two 2-D arrays, both of which include two arrays with the values 5, 3, 8 and 6, 1, 9.
  2. Display these arrays on the screen: first arr_1, then arr_2.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 4
toggle bottom row

book3-D Arrays

With three-dimensional arrays, everything is quite clear and logical. These arrays consist of elements that are two-dimensional arrays.

Let's practice to make it easier to understand.

Here's an example of how we can create a 3-D array with four 2-D arrays, each containing three 1D arrays with 2 elements:

123456789101112131415161718
import numpy as np # Creating array arr = np.array([ [ [1, 2], [4, 3], [7, 4] ], [ [2, 10], [9, 15], [7, 5] ], [ [1, 11], [3, 20], [0, 2] ], [ [9, 25], [6, 13], [9, 8] ] ]) # Displaying array print(arr)
copy

Let's now take a look at the visualization of this array:

Our 3D array is 4x3x2, hence why we have a rectangular parallelepiped with sides equal to 4, 3 and 2, respectively. The innermost 1D arrays lie along the axis 2 (e.g., [1, 2] or [4, 3]) where each small cube with side equal to 1 is a particular element (number).

Basically, all the elements of a 3D array are stored inside these innermost 1D arrays. The rectangular parallelepiped is just a visual representation for us to make things clear. The total number of elements (small cubes) is equal to 24 (the volume of the rectangular parallelepiped), which 4 * 3 * 2.

Note

Since its a 2D visualization of a 3D object, we cannot display and see here all the elements.

Time to test your strength!

Task

  1. You need to create two arrays:
    • the first one is a 2-D array containing two arrays with the values: 1, 5, 2 and 34, 2, 7;
    • the second one is a 3-D array (use only a single line to create this array) containing two 2-D arrays, both of which include two arrays with the values 5, 3, 8 and 6, 1, 9.
  2. Display these arrays on the screen: first arr_1, then arr_2.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

With three-dimensional arrays, everything is quite clear and logical. These arrays consist of elements that are two-dimensional arrays.

Let's practice to make it easier to understand.

Here's an example of how we can create a 3-D array with four 2-D arrays, each containing three 1D arrays with 2 elements:

123456789101112131415161718
import numpy as np # Creating array arr = np.array([ [ [1, 2], [4, 3], [7, 4] ], [ [2, 10], [9, 15], [7, 5] ], [ [1, 11], [3, 20], [0, 2] ], [ [9, 25], [6, 13], [9, 8] ] ]) # Displaying array print(arr)
copy

Let's now take a look at the visualization of this array:

Our 3D array is 4x3x2, hence why we have a rectangular parallelepiped with sides equal to 4, 3 and 2, respectively. The innermost 1D arrays lie along the axis 2 (e.g., [1, 2] or [4, 3]) where each small cube with side equal to 1 is a particular element (number).

Basically, all the elements of a 3D array are stored inside these innermost 1D arrays. The rectangular parallelepiped is just a visual representation for us to make things clear. The total number of elements (small cubes) is equal to 24 (the volume of the rectangular parallelepiped), which 4 * 3 * 2.

Note

Since its a 2D visualization of a 3D object, we cannot display and see here all the elements.

Time to test your strength!

Task

  1. You need to create two arrays:
    • the first one is a 2-D array containing two arrays with the values: 1, 5, 2 and 34, 2, 7;
    • the second one is a 3-D array (use only a single line to create this array) containing two 2-D arrays, both of which include two arrays with the values 5, 3, 8 and 6, 1, 9.
  2. Display these arrays on the screen: first arr_1, then arr_2.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 2. Chapter 4
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt