Instagram
youtube
Facebook
Twitter

Add Two NumPy Arrays Element-wise

     Add Two NumPy Arrays Element-wise
      
      Short Description of the Program:

      This program performs element-wise addition of two NumPy arrays using the np.add() function.
      
       Explanation:

  • np.array()
    Initializes two arrays with the same shape.

     
  • np.add(array1, array2)
    Adds each element in array1 to the corresponding element in array2.

     
  • print()
    Displays both input arrays and the result of the addition.

     

Program:

import numpy as np

array1 = np.array([[1, 2, 3], [4, 5, 6]])

array2 = np.array([[10, 20, 30], [40, 50, 60]])

result = np.add(array1, array2)

print("Array 1:\n", array1)

print("\nArray 2:\n", array2)

print("\nElement-wise Multiplication Result:\n", result)