- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return the dot product of One-Dimensional vectors in Python
To return the dot product of One-Dimensional vectors, use the numpy.vdot() method in Python. The vdot(a, b) function handles complex numbers differently than dot(a, b). If the first argument is complex the complex conjugate of the first argument is used for the calculation of the dot product. The vdot handles multidimensional arrays differently than dot: it does not perform a matrix product, but flattens input arguments to 1-D vectors first. Consequently, it should only be used for vectors.
The method returns the dot product of a and b. Can be an int, float, or complex depending on the types of a and b. The 1st parameter is a. If a is complex the complex conjugate is taken before calculation of the dot product. The b is the 2nd parameter to the dot product.
Steps
At first, import the required libraries −
import numpy as np
Creating two numpy One-Dimensional array using the array() method −
arr1 = np.array([2+3j,5+6j]) arr2 = np.array([9+10j,11+12j])
Display the arrays −
print("Array1...\n",arr1) print("\nArray2...\n",arr2)
Check the Dimensions of both the arrays −
print("\nDimensions of Array1...\n",arr1.ndim) print("\nDimensions of Array2...\n",arr2.ndim)
Check the Shape of both the arrays −
print("\nShape of Array1...\n",arr1.shape) print("\nShape of Array2...\n",arr2.shape)
To return the dot product of One-Dimensional vectors, use the numpy.vdot() method −
print("\nResult...\n",np.vdot(arr1, arr2))
Example
import numpy as np # Creating two numpy One-Dimensional array using the array() method arr1 = np.array([2+3j,5+6j]) arr2 = np.array([9+10j,11+12j]) # Display the arrays print("Array1...\n",arr1) print("\nArray2...\n",arr2) # Check the Dimensions of both the arrays print("\nDimensions of Array1...\n",arr1.ndim) print("\nDimensions of Array2...\n",arr2.ndim) # Check the Shape of both the arrays print("\nShape of Array1...\n",arr1.shape) print("\nShape of Array2...\n",arr2.shape) # To return the dot product of One-Dimensional vectors, use the numpy.vdot() method in Python. print("\nResult...\n",np.vdot(arr1, arr2))
Output
Array1... [2.+3.j 5.+6.j] Array2... [ 9.+10.j 11.+12.j] Dimensions of Array1... 1 Dimensions of Array2... 1 Shape of Array1... (2,) Shape of Array2... (2,) Result... (175-13j)
- Related Articles
- Return the dot product of two vectors in Python
- Return the dot product of two multidimensional vectors in Python
- Program to find out the dot product of two sparse vectors in Python
- Program to find dot product of run length encoded vectors in Python
- Return the cross product of two (arrays of) vectors in Python
- C++ Program for dot product and cross product of two vectors
- Return the outer product of two masked One-Dimensional Numpy arrays
- Return the inner product of two masked One-Dimensional arrays in Numpy
- Return the multiple vector cross product of two (arrays of) vectors in Python
- Return the cross product of two (arrays of) vectors with different dimensions in Python
- Get the Inner product of two One-Dimensional arrays in Python
- Get the Outer product of two One-Dimensional arrays in Python
- Get the Kronecker product of two One-Dimensional Arrays in Python
- Get the Inner product of a One-Dimensional and a Two-Dimensional array in Python
- Return the dot product of two masked arrays in Numpy
