# Numpy shape()

Numpy

``numpy.shape(shape, dtype=None, order='C')``
Return tuple with details of the array.
 `a` array input
Shape() returns a tuple giving shape of the array. Number of rows , columns and dimension of the array.

Let us check how different dimensional arrays returns the value as tuple when we use shape().
``````One Dimensional array ( 1-D )  : (n, ) :tuple elements = 1
Two Dimensional array ( 2-D )  : (n,m )   :tuple elements  = 2
Three Dimensional array ( 3-D) : (n,m,j)  : tuple elements  = 3
Four Dimensional array ( 4-D ) : (n,m,j,k): tuple  elements = 4 ``````
 Shape: (3, 4) Dimension 2 Shape: (4, 3) Dimension 2
You can read more on how to create arrays by using ones(). We will input different shapes to create the array by using ones().

Along with shape() we will display the dimainsion of the array by using ndim

## One dimensional array

``````import numpy as np
ar=np.ones((3,))
print(ar)
print("Shape: ", ar.shape)
print("Dimension ", ar.ndim)``````
Output
``````[1. 1. 1.]
Shape:  (3,)
Dimension  1``````

## Two dimensional array

``````import numpy as np
ar=np.ones((3,2))
print(ar)
print("Shape: ", ar.shape)
print("Dimension ", ar.ndim)``````
Output
``````[[1. 1.]
[1. 1.]
[1. 1.]]
Shape:  (3, 2)
Dimension  2``````

## Three dimensional array

``````import numpy as np
ar=np.ones((3,2,3))
print(ar)
print("Shape: ", ar.shape)
print("Dimension ", ar.ndim)``````
Output
``````[[[1. 1. 1.]
[1. 1. 1.]]

[[1. 1. 1.]
[1. 1. 1.]]

[[1. 1. 1.]
[1. 1. 1.]]]
Shape:  (3, 2, 3)
Dimension  3``````

## Four dimensional array

``````import numpy as np
ar=np.ones((3,2,3,4))
print(ar)
print("Shape: ", ar.shape)
print("Dimension ", ar.ndim)``````
Output
``````[[[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]

[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]]

[[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]

[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]]

[[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]

[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]]]
Shape:  (3, 2, 3, 4)
Dimension  4``````

Subscribe to our YouTube Channel here

## Subscribe

* indicates required
Subscribe to plus2net

plus2net.com