NumPy Array Shape
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) (2, 2,2)
The example above returns (2, 4) and (2,2,2) which means that the arr1 has 2 dimensions and each dimension has 4 elements. Similarly, arr2 has 3 dimensions and each dimension has 2 rows and 2 columns.
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.
Please Login to comment...