Page 293 - Ai_C10_Flipbook
P. 293

Type            Function                                  Example

                  Row wise &         ARR.
                  column wise        max(axis=1)      [1]:  import numpy as np
                  maximum value      for row                ARR = np.array([[11,2,13,4],[3,4,5,6]])
                                                            print("Rowwise max :",ARR.max(axis=1))
                                                            print("Column wise max :",ARR.max(axis=0))
                                     ARR.                   Rowwise max : [13  6]
                                     max(axis=0)            Column wise max : [11  4 13  6]
                                     for column

                  Row wise &         ARR.
                                                      [1]:  import numpy as np
                  column wise        min(axis=1)
                                                            ARR = np.array([[11,2,13,4],[3,4,5,6]])
                  minimum value      for row                print("Rowwise min :",ARR.min(axis=1))
                                     ARR.                   print("Column wise min :",ARR.min(axis=0))
                                     min(axis=0)            Rowwise min : [2 3]
                                     for column             Column wise min : [3 2 5 4]

                  Sum of all values   ARR.sum()
                                                      [1]:  import numpy as np
                  in the given array
                                                            ARR = np.array([[11,2,13,4],[3,4,5,6]])
                                                            print("Row Wise sum :",ARR.sum(axis=1))
                                                            print("Column wise sum :",ARR.sum(axis=0))
                                                            print("sum is :",ARR.sum())
                                                            Rowwise sum : [30 18]
                                                            Column wise sum : [14  6 18 10]
                                                            sum is : 48


                  Sorting the array  ARR.sort()
                                                      [1]:  a = np.array([12,4,-10,23,29,15, -1,45,33,37,-14])
                                                            #Creating a 1-D Numpy array
                                                            print(np.sort(a)) #Printing the sorted numpy array
                                                            #We can also sort array row wise and column wise!
                                                            b = np.array([[-9,5,18,9,12], [10,11,3,-5,-10]])
                                                            #Creating a 2-D Numpy array
                                                            print(np.sort(b, axis = 1)) #Axis = 1performs the
                                                            sorting function row-wise
                                                            print(np.sort(b, axis = 0)) #Axis = 0 performs the
                                                            sorting function columns-wise
                                                            [-14 -10  -1   4  12  15  23  29  33  37  45]
                                                            [[ -9   5   9  12  18]
                                                            [-10  -5   3  10  11]]
                                                            [[ -9   5   3  -5 -10]
                                                             [ 10  11  18   9  12]]



                         Pandas (PANel DAta)

                 Pandas is an open-source Python library used for data manipulation and analysis. It provides strong features for
                 working with three key data structures: Series (1-dimensional), DataFrame (2-dimensional), and Index (used for
                 label-based indexing). These structures allow smooth processing and analysis of data, regardless of its origin. In
                 Pandas, the data need not be labelled to be placed into a data structure.
                                                                                    Advance Python (Practical)  291
   288   289   290   291   292   293   294   295   296   297   298