How to implement element-wise addition,subtraction and multiplication in Numpy?
Array is a collection of similar data elements. When you implement the arithmetic operations, you have to do each element. Let us implement this as follows. Element-wise Arithmetic Operations in Numpy: It starts from importing numpy library. First, two arrays are included as input. Element wise operations are performed and result is printed. Code: import numpy as np1 # Two arrays as input s_arr1 = np1.array([11, 22, 33, 44]) s_arr2 = np1.array([5, 10, 15, 20]) # Arithmetic operations on element wise print("Element wise Arithmetic Operations:") print("Addition:", s_arr1 + s_arr2) print("Subtraction:", s_arr2 - s_arr1) print("Multiplication:", s_arr1 * s_arr2) Output: Element wise Arithmetic Operations: Addition: [16 32 48 64] Subtraction: [ -6 -12 -18 -24] ...