Python Numpy Array Shape














































Python Numpy Array Shape



Description
NumPy generally stands for Numerical Python and it is a general purpose array processing package.it always provides a high performance multidimensional array object. Numpy is usually for creating an array of n dimensions.

Methods :
The shape of an array can be defined as the number of elements in each dimension. we can say that dimension is the number of indices or subscripts, that we want in order to specify an individual element of an array. Now how can we get the shape of an array as in NumPy arrays to have an attribute called shape that returns a tuple with each index having the number of corresponding elements.
 
Syntax: numpy.shape(array_name)

Parameters: Array is passed as a Parameter.

Return: A tuple whose elements give the lengths of the corresponding array dimensions. the shape tuple represents the integers at every index that tells about the number of the elements the dimension has as we have index 4 we have value 4 so that we can say that the 5th(4+1th) dimension has 4 elements.

Example :
Code :
import numpy as np arr = np.array([[8,2,1,4], [5, 3, 7, 9]]) print(arr.shape)

Output


Example :
Code :
import numpy as np arr = npy.array([3,6,9,12,15], ndmin=6) print(arr) print('shape of an array :', arr.shape)

Output




Comments