1. Help Center
  2. Python Programming

How will you find the shape of any given NumPy array?

We can use the shape attribute of the numpy array to find the shape. It returns the shape of the array in terms of row count and column count of the array.
 
import numpy as np

arr_two_dim = np.array([("x1","x2", "x3","x4"),

("x5","x6", "x7","x8" )])

arr_one_dim = np.array([3,2,4,5,6])

# find and print shape

print("2-D Array Shape: ", arr_two_dim.shape)

print("1-D Array Shape: ", arr_one_dim.shape)

"""

Output:

2-D Array Shape: (2, 4)

1-D Array Shape: (5,)