What are the different methods to find the shape of a Numpy array?

To determine the shape of a NumPy array, you can utilize the shape attribute, which provides a tuple representing the number of rows and columns. For instance, a 3x4 array will yield a shape of (3, 4). The shape attribute is essential for understanding array dimensions and enabling diverse operations.

Here is an example code of how you can use the shape attribute:

This is just one method of finding the shape of an array, if you have other alternate methods and techniques, feel free to share them below!

Hi @Hyder_Zaidi, another method of finding the shape is by utilizing the np.size() function. This function can be used to count the number of elements along each axis, providing a tuple of dimensions for the 2D array and a single-element tuple for the 1D array.

Note: You have to specify each axis separately. For example, if you have three axes, you would also specify np.size(array, 2) to find the dimensions along the third axis.

Hello @Hyder_Zaidi, the approach I use often involves using the np.shape() function to determine the shape of my NumPy arrays. This method returns a tuple with the number of rows and columns.

Hope this helps you!