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

Conteúdo do Curso

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!

Tarefa
test

Swipe to show code editor

  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 desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 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!

Tarefa
test

Swipe to show code editor

  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 desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 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!

Tarefa
test

Swipe to show code editor

  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 desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu 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!

Tarefa
test

Swipe to show code editor

  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 desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 2. Capítulo 4
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt