Instagram
youtube
Facebook
Twitter

Compute the Dot Product of Two NumPy Arrays

    Compute the Dot Product of Two NumPy Arrays
     
     Short Description of the Program:

     This program computes the dot product of two NumPy arrays using the np.dot() function.
   
     Explanation:

  • np.array()
    Creates two 2D arrays suitable for matrix multiplication.

     
  • np.dot(array1, array2)
    Performs the dot product, which multiplies rows of the first array with columns of the second and sums them.

     
  • print()
    Displays both input arrays and the resulting matrix after the dot product.

     

Program:

import numpy as np

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

array2 = np.array([[5, 6], [7, 8]])

dot_product = np.dot(array1, array2)

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

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

print("\nDot Product Result:\n", dot_product)