NumPy was created in 2005 by Travis Oliphant by combining features of Numarray into Numeric package.
Its main objects are multi-D array. It is a table of elements, indexed by a tuple of positive integers.
Axes : NumPy Dimensions
Rank : No. of axes
For e.g.
[[1, 0, 0],
[0, 1, 2]]
In this example: –
- 1st dimension has axis has length = 2
- 2nd dimension has axis has length = 3
- Rank = 2(2-Dimensional)
NumPy array class is known as ndarray.
Attributes of ndarray class :
- ndarray.ndim : Rank of array i.e. number of axes of the array.
- ndarray.shape : dimensions of array. This is a tuple of integers indicating the size of array.
(n, m) : n(rows), m(column). - ndarray.size : Total number of elements in the array (n * m).
- ndarray.dtype : An object describing the type of elements in the array. One can create or specify data types using standard Python types. e.g. numpy.int 32, numpy.float 64
- ndarray.itemsize : dtype/8 – Equivalent to ndarray.dtype.itemsize.
- ndarray.data : actual elements of the array are stored in this buffer.
Code : Python Program illustrating working of ndarray class :
# Python Program illustrating the working of ndarray class
import numpy as np
# Array declaration
a = np.arange(10).reshape(2, 5)
print("array : \n", a)
# use of ndarray.shape
print("\nndarray.shape : ", a.shape, "\n")
# use of ndarray.ndim
print("ndarray.ndim : ", a.ndim, "\n")
# use of ndarray.dtype
print("ndarray.dtype : ", a.dtype, "\n")
# use of ndarray.size
print("ndarray.size : ", a.size, "\n")
# use of ndarray.itemsize - dtype/8
print("ndarray.itemsize : ", a.itemsize, "\n")
Output :
array : [[0 1 2 3 4] [5 6 7 8 9]] ndarray.shape : (2, 5) ndarray.ndim : 2 ndarray.dtype : int32 ndarray.size : 10 ndarray.itemsize : 4
By Mohit_OMG :)



