Introduction
One of the main method which is available or a more suitable term is actually main attribute of the NumPy array is dimension. So, there is a certain definition for dimension actually in the context of the NumPy array. There are several definition regarding on NumPy array dimension’s definition. But the simple understanding for the definition of dimension is the number of the axis for each additional nested array. Another definition exist in several articles about dimension is that a dimension in arrays is one level of depth (nested arrays), where the nested arrays are arrays that have arrays as their elements.
How to Show Dimension of a NumPy Array
In order to do that, just take a look in the article with the title of ‘How to Use NumPy’ in this link. That article will direct and give detail descriptions on the information about how to use NumPy library. After ensuring the requirement for using NumPy library, just do and follow steps below. Actually, it will give and also it will go into the description parts of how to show a dimension of NumPy array, below is an example as a simulation :
-
First of all, just execute the Command Prompt. Since it is actually using a a local device with Microsoft Windows as the operating system. Below is the execution of the Command Prompt :
Microsoft Windows [Version 10.0.22000.856] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal>
-
Next, type ‘python’ in the Command Prompt to get into the Python command console :
Microsoft Windows [Version 10.0.22000.856] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal>python Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
-
Finally, the final step is to define the NumPy arrays. Following after, just check the dimension of the NumPy arrays by executing ndim attribute from the NumPy arrays variable as it exist below :
Microsoft Windows [Version 10.0.22000.856] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal>python Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy as np >>> numpy_array_zero_dimension = np.array(1) >>> print(numpy_array_zero_dimension.ndim) 0 >>> numpy_array_one_dimension = np.array([1,2,3,4,5]) >>> print(numpy_array_one_dimension.ndim) 1 >>> numpy_array_two_dimension = np.array([[1,2,3,4,5],[6,7,8,9,10]]) >>> print(numpy_array_two_dimension.ndim) 2 >>>