Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Creating Higher Dimensional Arrays | NumPy Basics
Ultimate NumPy

Deslize para mostrar o menu

book
Creating Higher Dimensional Arrays

2D Arrays

Let's now create a higher dimensional array, namely a 2D array:

1234
import numpy as np # Creating a 2D array array_2d = np.array([[1, 2, 3], [4, 5, 6]]) print(f'2-dimensional array: \n{array_2d}')
copy

Basically, creating a higher-dimensional NumPy array involves passing a higher-dimensional list as the argument of the array() function.

Note

Any NumPy array object is called an ndarray.

Here is a visualization of our 2D array:

We can think of it as a 2x3 matrix.

3D Array

Creating 3D arrays is nearly identical to creating 2D arrays. The only difference is that we now need to pass a 3D list as an argument:

12345678
import numpy as np # Creating a 3D array array_3d = np.array([ [[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[10, 11, 12], [13, 14, 15], [16, 17, 18]], [[19, 20, 21], [22, 23, 24], [25, 26, 27]] ]) print(f'3-dimensional array: \n{array_3d}')
copy

However, visualizing a 3D array is a bit more complex, but it can still be done:

The array is 3x3x3, which is why we have a cube with each side equal to 3.

In practice, the approach to handling 3D and higher-dimensional arrays is no different from handling 2D arrays.

Tarefa

Swipe to start coding

Create a 2D array using lists. This array can have any number of rows and columns, with arbitrary values.

Solução

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 1. Capítulo 3
Sentimos muito que algo saiu errado. O que aconteceu?

Pergunte à IA

expand
ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

book
Creating Higher Dimensional Arrays

2D Arrays

Let's now create a higher dimensional array, namely a 2D array:

1234
import numpy as np # Creating a 2D array array_2d = np.array([[1, 2, 3], [4, 5, 6]]) print(f'2-dimensional array: \n{array_2d}')
copy

Basically, creating a higher-dimensional NumPy array involves passing a higher-dimensional list as the argument of the array() function.

Note

Any NumPy array object is called an ndarray.

Here is a visualization of our 2D array:

We can think of it as a 2x3 matrix.

3D Array

Creating 3D arrays is nearly identical to creating 2D arrays. The only difference is that we now need to pass a 3D list as an argument:

12345678
import numpy as np # Creating a 3D array array_3d = np.array([ [[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[10, 11, 12], [13, 14, 15], [16, 17, 18]], [[19, 20, 21], [22, 23, 24], [25, 26, 27]] ]) print(f'3-dimensional array: \n{array_3d}')
copy

However, visualizing a 3D array is a bit more complex, but it can still be done:

The array is 3x3x3, which is why we have a cube with each side equal to 3.

In practice, the approach to handling 3D and higher-dimensional arrays is no different from handling 2D arrays.

Tarefa

Swipe to start coding

Create a 2D array using lists. This array can have any number of rows and columns, with arbitrary values.

Solução

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 1. Capítulo 3
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Sentimos muito que algo saiu errado. O que aconteceu?
some-alt