How to check shape of NumPy array

You can check the shape of the NumPy array with the following code. If you want to learn Python, I highly recommend reading This Book.

How to check shape of NumPy array
How to check shape of NumPy array

Example 1

import numpy as np

a = np.array([[5,10,15],[20,25,30]])

print(a.shape)

Output:

(2, 3)

Example 2

import numpy as np

a = np.array([[5,1]])

print(a.shape)

Output:

(1, 2)

Example 3

import numpy as np

a = np.array([5,10,15])

print(a.shape)

Output:

(3,)

Example 4

import numpy as np

a = np.array([[5,10,15,20],[20,25,30,50],[35,40,45,60]])

print(a.shape)

Output:

(3, 4)

Example 5

import numpy as np

a = np.array([[[5,10,15,20],[20,25,30,50],[35,40,45,60]]])

print(a.shape)

Output:

(1, 3, 4)

People are also reading:

Best Python Books

What is Computer Vision? Examples, Applications, Techniques

Books for Machine Learning (ML)

Free Learning Resources

Leave a Comment

Your email address will not be published.