Page 189 - Robotics and AI class 10
P. 189
Task
#Experiential Learning
Type "import this" in your Python IDLE and you will find a poem written by Tim Peters, a major contributer
to the Python community.
Using Mathematical operators on integer array:
Operator Syntax Output
** import numpy as np [1 2 9 4]
(exponential) marks1 = np.array([1,2,3,4]) marks1 to the power of 3
marks2=np.array([2,1,2,1]) is : [ 1 8 27 64]
print(marks1**marks2)
print("marks1 to the power of 3 is
:",marks1**3)
+ import numpy as np [12 14 9 11]
(Addition) marks1 = np.array([7,8,5,4]) 2 marks extra : [ 9 10
marks2=np.array([5,6,4,7]) 7 6]
print(marks1+marks2)
print("2 marks extra: ",marks1+2)
- import numpy as np [ 2 2 1 -3]
(subtraction) marks1 = np.array([7,8,5,4]) 2 marks deducted : [5 6
marks2=np.array([5,6,4,7]) 3 2]
print(marks1-marks2)
print("2 marks deducted :",marks1-2)
* import numpy as np [35 48 20 28]
(Multiplication) marks1 = np.array([7,8,5,4]) 2 marks multiplied : [14
marks2=np.array([5,6,4,7]) 16 10 8]
print(marks1*marks2)
print("2 marks multiplied
:",marks1*2)
/ import numpy as np [ 5. 5. 10. 8.]
(divide) marks1 = np.array([10,20,30,40]) 2 marks divided : [ 5.
marks2=np.array([2,4,3,5]) 10. 15. 20.]
print(marks1/marks2)
print("2 marks divided :",marks1/2)
Introduction to Data and Programming with Python 187

