Why NumPy? ========== NumPy is a third party module/package/library which we can to use to perform the complex math operations with array computing. Array: ===== It is a collection/sequence of similar data items (homogeneous elements). ex: [1,2,3,4], {1.2,2.3,3.4},(9-7j,9+7j,7-5j,7+5j) etc. Q: In Python, how we can store/represent with the similar data items? ===================================================================== List ==> Homogeneous elements/Heterogeneous elements Mutable Insertion order can be preserved Tuple ==> Homogeneous elements/Heterogeneous elements Immutable Insertion Order can be preserved Set ==> Homogeneous elements/Heterogeneous elements Mutable (add()) and/or Immutable Cannot preserve the order. Python List Vs Numpy: ===================== In Python: list of built-in datatypes: int float complex Bool str list tuple set frozenset bytes bytearray None In NumPy: we have only one built-in datatype which we can use to define: 1D array ==> Arranging of elements in either row or column format. 2D array ==> Arranging of elements in both row and column ND Array ==> Multi dimensional array i.e., "ndarray" is also a class ndarray is used to store homogeneous elements only. IDEs available for NumPy as default: ==================================== Jupyter Anaconda Jupyter notebook List Vs ndarray: ================ List data elements cannot reserve the continuous memory in heap section. list to array: ============== array(): we can convert the list data into an array Syntax: import numpy numpy.array(list-data) Getting the size of the memory: =============================== getsizeof() =========== ==> a built-in function used to get the size of the memory for any object. ==> defined in the module: "sys" ==> to use this "getsizeof()", we must be import "sys" module. Syntax: import sys sys.getsizeof(object-name) import sys import numpy ld = [1,2,3,4,5,6,7,8,9,10,11,12] print(ld,type(ld),id(ld)) print("The Memory Size of given list data is = ",sys.getsizeof(ld)) print(id(ld[0]),id(ld[1]),id(ld[2])) # converting the list into an array a = numpy.array(ld) print(a,type(a),id(a)) print("The Memory size of given array is = ",sys.getsizeof(a)) print(id(a[0]),id(a[1]),id(a[2]))