Why NumPy? ========== 1) Python List ==> reserve with non-contiguous memory. NumPy-ndarray ==> reserve with contiguous memory. 2) Python-List will consume more time and performance get disturbed. NumPy-ndarray will consume less time and performance is good. 3) Python: 10+ datatypes ==> Heterogeneous datatypes NumPy: 1-datatype ==> ndarray import sys import numpy a = 123 b = 1.23 c = 1-2j d = True e = "python" f = [1,2,3,4,5] g = (2,3,4,5,6) arr = numpy.array(f) arr1 = numpy.array([1.2,2.3,3.4,4.5,5.6]) print("The Size of all the above data definitions are = ") print(sys.getsizeof(a)) print(sys.getsizeof(b)) print(sys.getsizeof(c)) print(sys.getsizeof(d)) print(sys.getsizeof(e)) print(sys.getsizeof(f)) print(sys.getsizeof(g)) print(sys.getsizeof(arr)) print(sys.getsizeof(arr1)) =============================================================== ndarray: ======== built-in datatype in NumPy a pre-defined class: ndarray ndarray ====== ==> most important object in NumPy. ==> N-dimensional Array Type ==> describe a collection of items of the same type ==> which can be accessed using a zero-based index. dtype ===== ==> Each item of ndarray takes the same size of a memory block. ==> datatype object array Scalar type ================= ==> any item can be extracted from an ndarray by using slicing is represented by a python object of an array called as "array scalar type". ============================= How to create an ndarray? ========================= [1,2,3] ==> 1d-array ==> row [1 2 3] == ; 1-d array ==> column array(): ======== Syntax: import numpy numpy.array(object, dtype = None, copy = True, order = None, subok = False, ndmin = 0) order: ====== C ==> row major F ==> Column major A ==> Any 1-D array: ========= Syntax: numpy.array([list/tuple]) 2-D array: ========== Syntax: numpy.array([[1d],[1d],[1d],...[1d]]) 3-D array: ========= Syntax: numpy.array([[2d],[2d],[2d],...[2d]]) import numpy as rk # creating an array with array() by consider the only object parameter a = rk.array((1,2,3,4))# 1-d array print(a,type(a)) b = rk.array(10) print(b,type(b)) # 2D-array # Collection of more than one 1-d array ==> 2d-array c = rk.array([[1,2,3],[4,5,6]]) print(c,type(c)) d = rk.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]]) print(d,type(d)) # 3-d array # collection of 2-d arrays e = rk.array([[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]]]) print(e,type(e))