{"id":25704,"date":"2021-12-04T09:19:26","date_gmt":"2021-12-04T03:49:26","guid":{"rendered":"https:\/\/python-programs.com\/?p=25704"},"modified":"2021-12-04T09:19:26","modified_gmt":"2021-12-04T03:49:26","slug":"python-program-to-calculate-the-dot-product","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-the-dot-product\/","title":{"rendered":"Python Program to Calculate the Dot Product?"},"content":{"rendered":"

Dot Product:<\/h4>\n

The dot product, commonly known as the scalar product in mathematics, is an algebraic operation that takes two equal-length sequences of numbers and produces a single number.<\/p>\n

Given two vectors A and B, we must find the dot product of the two vectors.<\/p>\n

For Example :<\/strong><\/p>\n

Let A = a1i+a2j+a3k<\/p>\n

B= b1i+b2j+b3k<\/p>\n

Where<\/p>\n

i<\/strong> is the unit vector along the x-axis.<\/p>\n

j<\/strong> is the unit vector along the y-axis.<\/p>\n

k<\/strong> is the unit vector along the z-axis.<\/p>\n

The Formula to calculate the dot product<\/h4>\n
Dot product = a1*b1+a2*b2+a3*b3<\/pre>\n

Calculating Dot Product of Two Vectors in Python<\/h4>\n

The numpy.dot() method of the numpy library provides an efficient way to find the dot product of two sequences.<\/p>\n

numpy.dot() is a method that accepts two sequences as arguments, whether they are vectors or multidimensional arrays, and displays the output, which is the dot product. To use this approach, we must first import Python’s numpy module.<\/p>\n

Syntax:<\/strong><\/p>\n

numpy.dot(vector_a, vector_b, out = None )<\/pre>\n

Parameters<\/strong><\/p>\n

vector_a:<\/strong> It is an array. If a<\/strong> is complex, its complex conjugate is utilized to compute the dot product.<\/p>\n

vector_b: <\/strong>It is an array. If b\u00a0<\/strong>is complex, its complex conjugate is utilized to compute the dot product.<\/p>\n

out: <\/strong>It is an array. This is optional. The output parameter must be C-contiguous, and its datatype must be the same as the datatype\u00a0returned by dot (a,b).<\/p>\n

Return Value:<\/strong><\/p>\n

Returns the Dot Product of given vectors a and b. Scalar is returned if vector a and vector b are both 1D.<\/p>\n

How to find the Dot Product of Scalars?<\/h4>\n

Given two scalar values and use numpy.dot() function to display their dot product.<\/p>\n

Approach:<\/strong><\/p>\n