Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 156 - 2615_KEC
P. 156

    Output
                       [12 14 9 11]
                       2 marks extra: [ 9 10 7 6]

                         The - (Subtraction) operator: This operator is used to subtract one array element from another
                        or subtract a constant from each element.

                          Program.py
                       File  Edit  Format    Run   Options   Window    Help

                       import numpy as np
                       marks1 = np.array([7,8,5,4])
                       marks2=np.array([5,6,4,7])
                       print(marks1-marks2)
                       print("2 marks deducted:",marks1-2)

                          Output

                       [ 2 2 1 -3]
                       2 marks deducted: [5 6 3 2]

                         The * (Multiplication) operator: This operator is used to multiply array elements or multiply
                        each element by a constant.

                          Program.py
                       File  Edit  Format    Run   Options   Window    Help

                       import numpy as np
                       marks1 = np.array([7,8,5,4])
                       marks2=np.array([5,6,4,7])
                       print(marks1*marks2)
                       print("2 marks multiplied:",marks1*2)

                          Output

                       [35 48 20 28]
                       2 marks multiplied: [14 16 10 8]

                         The / (Division) operator: This operator is used to divide array elements or divide each element
                        by a constant, resulting in a quotient.
                          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 divided:",marks1/2)

                      154   Premium Edition-VIII

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