Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 157 - 2615_KEC
P. 157

    Output
                      [ 5. 5. 10. 8.]
                      2 marks divided: [ 5. 10. 15. 20.]

                       The //(Floor division) operator: This operator is used to divide two numbers and return the
                       quotient rounded down to the nearest integer.

                         Program.py
                      File  Edit  Format   Run    Options   Window    Help

                      import numpy as np
                      marks1 = np.array([10,20,30,40])
                      marks2=np.array([2,4,3,5])
                      print(marks1//marks2)
                      print("2 marks floor division:",marks1//2)

                         Output
                      [ 5 5 10 8]
                      2 marks floor division: [ 5 10 15 20]

                       The % (Modulus) operator: This operator is used to find the remainder when one array element
                       is divided by another or by a constant.
                         Program.py

                      File  Edit  Format   Run    Options   Window    Help

                      import numpy as np
                      marks1 = np.array([10,20,30,40])
                      marks2=np.array([1,2,3,4])
                      print(marks1%marks2)
                      print("remainder of division:",marks1%3)

                         Output

                      [0 0 0 0]
                      remainder of division: [1 2 0 1]

                     INDEXING

                     Array indexing in NumPy refers to the method of accessing specific elements or subsets of data

                     within an array. Indexing allows us to retrieve, modify and manipulate data at specific positions or
                     ranges helps in making it easier to work with large datasets. The different ways to index and slice
                     NumPy arrays to work with our data more effectively.

                                                                                   NumPy-Creation, Selection & Operation  155

| 152 153 154 155 156 157 158 159 160 161 162 |