Python NumPy Shape – Python NumPy
Python NumPy array shape Function
The NumPy shape function helps to find the number of rows and columns of python NumPy array. The numpy.shape() function gives output in form of tuple (rows_no, columns_no).
Syntax: np.shape(array)
The shape of a Numpy 1D array
1 2 3 4 5 6 |
|
1 2 3 4 5 |
|
When you will find the shape of NumPy one dimensional array then np.shape() give a tuple which contains a single number. That number shows the column number respected to the array.
The shape of a Numpy 2D array
1 2 3 4 5 |
|
1 2 3 4 5 6 7 |
|
The np.shape() gives a return of two-dimensional array in a pair of rows and columns tuple (rows, columns).
The shape of a Numpy 3D array
1 2 3 4 5 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
The np.shape() gives a return of three-dimensional array in a tuple (no. of 2D arrays, rows, columns).
Python NumPy array shape using shape attribute
Above you saw, how to use numpy.shape() function. Instead of it, you can use Numpy array shape attribute.
Syntax: array.shape
1 2 |
|
1 |
|
Python NumPy array shape vs size
Most of the people confused between both functions. NumPy array shape gives the shape of a NumPy array and Numpy array size function gives the size of a NumPy array.
Click here to learn more about Numpy array size.
Question: Find the shape of below array and print it.
1 2 3 4 5 6 |
|
Solution:
1 2 |
|
1 |
|
Multiply sea night grass fourth day sea lesser rule open subdue female fill which them Blessed, give fill lesser bearing multiply sea night grass fourth day sea lesser
Emilly Blunt
December 4, 2017 at 3:12 pm