Updated April 15, 2023

## Introduction to NumPy 3D array

Arrays in NumPy are data structures with high performance suitable for mathematical operations. The three levels of arrays nested inside one another represent the three-dimensional array in Python, where each level means one dimension. We use the array function in NumPy to create a three-dimensional array with an object as the parameter passed to it. NumPy represents a three-dimensional array as an object with nested lists, where x represents the outermost list, y represents the lists nested inside x, and z represents the values inside each y-nested list. So in this topic, we will learn about NumPy 3D array.

**Syntax:**

The syntax for NumPy 3D array in Python is as follows:

`numpy.array(object)`

In NumPy, you can create a three-dimensional array by creating an object that represents x by y by z, where x represents the outermost list, y represents the lists nested inside x, and z represents the values inside each y-nested list.

### Declaring the NumPy 3D array

- Arrays in NumPy are data structures with high performance suitable for mathematical operations. For example, the three levels of arrays nested inside one another represent the three-dimensional array in Python.
- Each level in the three-dimensional array represents one dimension. We use the array function in NumPy to create a three-dimensional array with an object as the parameter passed to it.
- The NumPy package represents a three-dimensional array as an object with nested lists, where x represents the outermost list, y represents the lists nested inside x, and z represents the values inside each y-nested list.
- Consider the representation of a three-dimensional array in Python below:

([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])

Here x = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]],

y = [[1, 2], [3, 4]] and [[5, 6], [7, 8]],

z = [1, 2], [3, 4] and [5, 6], [7, 8]

### Example of NumPy 3D array

Given below are the examples of NumPy 3D array:

#### Example #1

Python program to demonstrate NumPy three dimensional array using array function in NumPy and passing an object as a parameter to it and then to display the elements of the array on the screen:

**Code:**

```
#importing the package numpy as pynum
import numpy as pynum
#creating a three dimensional array using the array function and storing it in the variable called threedimarray
threedimarray = pynum.array([[[10,20,30,40], [50,60,70,80]]])
#displaying the elements of the newly created three dimensional array followed by an one line space
print 'The elements of the newly created three-dimensional array are:'
print '\n'
print threedimarray
print '\n'
```

**Output:**

In the above program, we are importing a package in Python called NumPy as pynum. Importing the NumPy package enables us to use the array function in Python. To create a three-dimensional array in Python, we pass an object representing x by y by z, where x represents the nested lists, y represents the nested lists inside the x nested lists, and z represents the values inside each y nested list. The newly created three-dimensional array is stored in the variable called threedimarray. The program then displays the elements of the newly created three-dimensional array, threedimarray, on the screen.

#### Example #2

Python program to demonstrate NumPy three dimensional array using array function in NumPy and passing an object as a parameter to it and then to display the elements of the array on the screen:

**Code:**

```
#importing the package numpy as pynum
import numpy as pynum
#creating a three dimensional array using the array function and storing it in the variable called threedimarray
threedimarray = pynum.array([[[10,20], [30,40], [50,60], [70,80]]])
#displaying the elements of the newly created three dimensional array followed by an one line space
print 'The elements of the newly created three dimensional array are:'
print '\n'
print threedimarray
print '\n'
```

**Output:**

In the above program, we are importing a package in Python called NumPy as pynum. Importing the NumPy package enables us to use the array function in Python. To create a three-dimensional array in Python, we pass an object representing x by y by z, where x represents the nested lists, y represents the nested lists inside the x nested lists, and z represents the values inside each y nested list. The newly created three-dimensional array is stored in the variable called threedimarray. The program then displays the elements of the newly created three-dimensional array, threedimarray, on the screen.

#### Example #3

Python program to demonstrate NumPy three dimensional array using array function in NumPy and passing an object as a parameter to it and then to display the elements of the array on the screen:

**Code:**

```
#importing the package numpy as pynum
import numpy as pynum
#creating a three dimensional array using the array function and storing it in the variable called threedimarray
threedimarray = pynum.array([[[10], [40], [60], [70]]])
#displaying the elements of the newly created three dimensional array followed by an one line space
print 'The elements of the newly created three dimensional array are:'
print '\n'
print threedimarray
print '\n'
```

**Output:**

In the above program, we are importing a package in Python called NumPy as pynum. Importing the NumPy package enables us to use the array function in Python. To create a three-dimensional array in Python, we pass an object representing x by y by z, where x represents the nested lists, y represents the nested lists inside the x nested lists, and z represents the values inside each y nested list. The program stores the newly created three-dimensional array in a variable called threedimarray. The program displays the elements of the newly created three-dimensional array, threedimarray, on the screen.

### Recommended Articles

This is a guide to NumPy 3D array. Here we discuss the concept of NumPy 3D array in Python through definition, syntax, and declaration of the 3D array in Python through programming examples and their outputs. You may also have a look at the following articles to learn more –