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.
- Draw Shape inside Shape in Python Using Turtle
- Program to print the diamond shape
- Python | Pandas df.size, df.shape and df.ndim
- Python | Pandas TimedeltaIndex.shape
- Python | Pandas Series.shape
- Python | Pandas Panel.shape
- Python | Pandas Index.shape
- PyQt5 - Tube shape Radio button
- PyQt5 QCalendarWidget - Changing Cursor Shape
- PyQt5 QCalendarWidget - Getting Cursor Shape
- PyQt5 QCalendarWidget - Making Cursor Shape back to normal
- turtle.shape() function in Python
- Python - tensorflow.IndexedSlices.shape Attribute
- TensorFlow - How to create a tensor of all ones that has the same shape as the input tensor
- PYGLET – Shape Width
- PYGLET – Shape X, Y Co-ordinates
- PYGLET – Shape Visible
- PYGLET – Shape Rotation
- PYGLET – Shape Position
- PYGLET – Shape Opacity
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.