Dimensions in Numpy Arrays

Dimensions of an array in NumPy are also called the Rank of an Array. Here, we will see how to check how many dimensions an array has used with the numpy.ndarray.ndim. With that, we will also see some examples of creating 0D, 1D, 2D, and 3D arrays:

  • Create a 0-Dimensional NumPy array and check the dimensions
  • Create a 1-Dimensional NumPy array and check the dimensions
  • Create a 2-Dimensional NumPy array and check the dimensions
  • Create a 3-Dimensional NumPy array and check the dimensions

Create a Zero-dimensional NumPy array

Let us create a zero-dimensional numpy array and check the dimensions using the ndim attribute:

Output

Create a One-dimensional NumPy array

Let us create a one-dimensional numpy array and check the dimensions using the ndim attribute:

Output

Create a Two-dimensional NumPy array

Let us create a two-dimensional numpy array and check the dimensions using the ndim attribute. A 2D NumPy array is like a matrix. Let us see an example to create a 2D NumPy array:

Output

Video Tutorial

Create a Three-dimensional NumPy array

Let us create a three-dimensional numpy array and check the dimensions using the ndim attribute. A 3D array has 2D arrays as elements i.e. matrix as elements. Let us see an example to create a 3D NumPy array:

Output

Video Tutorial

Check how many dimensions an array has

Let us see our last example to check the dimensions of two arrays:

Output

Video Tutorial

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others:

For Videos, Join Our YouTube Channel: Join Now


Read More:

Create numpy arrays
Initialize Numpy arrays
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading