Arrays are a regularly used concept in programming, particularly in data operations and manipulation. Because generally data is stored in terms of array and programmers perform some operations on that array to get desired data.
Python provides a multi-dimensional array in the NumPy library. So in this article, we will extract particular data from the 3D array. There are many ways to extract data from NumPy 3D array but here we will use slicing, indexing and negative index.
NumPy 3D Array
We have to extract the highlight value from the 3D array given below. There are several methods that can be used to extract the highlighted element. Some of which you will see further in this article.
array3D = np.array([[[10,11,12],[13,14,15],[16,17,18]], [[20,21,22],[23,24,25],[26,27,28]], [[30,31,32],[33,34,35],[36,37,38]]])
Method-01:
Using Slicing
array3D[1:2,1:2]
Output:
array([[[23, 24, 25]]])
Method-02:
Using Slicing
array3D[1,1]
Output:
array([23, 24, 25])
Method-03:
Using Array Index
array3D[1][1]
Output:
array([23, 24, 25])
Method-04:
Using Negative Index
array3D[-2][-2]
Output:
array([23, 24, 25])