We will find dot product by two methods. One by using np.dot function and passing the vectors in it and also by using @ which is used to finding dot product. Show
In this article, I will explain the Python dot() function and using this syntax how we can find out the dot product of 0-D arrays, 1-D arrays, and 2-D arrays with examples. 1. Quick Examples of NumPy dot ProductIf you are in a hurry, below are some quick examples of python NumPy dot product.
2. Syntax of numpy.dot()Following is the syntax of dot().
2.1 Parameters of dot()Following are the parameters of the dot() function.
2.2 Return Value of the dot()It returns the dot product of given NumPy arrays. If arr and arr1 are scalars or both the arrays are 1-Dimensional it returns a scalar. Otherwise, it returns an array. Note: The ValueError occurs when the last dimension of arr is not having the same size as the second-to-last dimension of arr1. 3. Usage of NumPy dot() FunctionPython NumPy module provides a dot() is a mathematical function and is used to compute the product of two arrays. It returns a scalar or array it depends upon the dimensions of the array. 3.1 Get the Dot Product of Two ScalarsIf either arr or arr1 is 0-D(scalar) then 1 is equivalent to 2 two numbers (a * b).
3.2 Get the Dot Product of Two Complex NumbersWe can also find the dot product of two complex numbers using 3. For that, we will pass the complex numbers as a parameter to this function and it will return the dot product of two complex numbers.
The following is an explanation of how you get this result.
4. Get Dot Product of 1-D NumPy ArraysLet’s take two 1-D arrays and find the dot product of two arrays, it returns a scalar value. First, create an NumPy array using np.array().
5. Get Dot Product of 2-D ArraysThe dot product of two 2-Dimensional arrays is the same as matrix multiplication, it will return the matrix multiplication of the two input arrays. Let’s take an example,
The following calculation is shown 2-D matrix multiplication.
6. ConclusionIn this article, I have explained the Python NumPy 3 function and using this how we can get the dot product of scalar values, 1-D arrays, and 2-D arrays with examples. |