Instagram
youtube
Facebook
Twitter

Multiply Two NumPy Arrays Element-wise

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

     This program multiplies two NumPy arrays element by element using the np.multiply() function.
     
      Explanation:

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

     
  • np.multiply(array1, array2)
    Multiplies each element in array1 with the corresponding element in array2.

     
  • print()
    Displays the input arrays and the resulting array.

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.multiply(array1, array2)

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

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

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