Python numpy.shape()

Here I’ll talk to you about python numpy shape() function. It returns the shape of an array. It is also used to reshape an array. To reshape an array ,using shape function, we just assign a tuple of array dimensions to it.



It can be used in two ways





python numpy shape() function takes single parameter

ar: it is the array, whose shape we want to find.


Check the examples below to understand

Example #1

In this example you can see we can check shape of an array in two ways


Example #2

Here, you see how to reshape an array using shape() function.



we can assign a tuple to reshape of an array with the values which will be the multiple of current tuple values.  In upper example you can see our previous shape was (4,1) . the multiply of 4×1=4.  and we assign a new to tuple (2, 2) to reshape the existing array. the multiply of 2×2=4. 


Check the example below if the multiple of assigning tuple will not be same it will be generate error





Start with Numpy

Python numpy ndim() function