The shape of an array can be defined as the number of elements in each dimension. Dimension is the number of indices or subscripts, that we require in order to specify an individual element of an array.
How can we get the Shape of an Array?
In NumPy we will use an attribute called shape which returns a tuple, the elements of the tuple give the lengths of the corresponding array dimensions.
Parameters: Array is passed as a Parameter.
Return: A tuple whose elements give the lengths of the corresponding array dimensions.
Example 1: (Printing the shape of the multidimensional array)
(2, 4) (3, 4)
The example above returns (2, 4) and (3,4) which means that the arr1 has 2 dimensions and each dimension has 4 elements. Similarly, arr2 has 3 dimensions and each dimension has 4 elements.
Example 2: (Creating an array using ndmin using a vector with values 2,4,6,8,10 and verifying the value of last dimension)
[[[[[[ 2 4 6 8 10]]]]]] shape of an array : (1, 1, 1, 1, 1, 5)
In the above example, we verified the last value of dimension as 5.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course