Friday, December 27, 2024
Google search engine
HomeLanguagesnumpy.vdot() in Python

numpy.vdot() in Python

Prerequisite – numpy.dot() in Python
numpy.vdot(vector_a, vector_b) returns the dot product of vectors a and b. If first argument is complex the complex conjugate of the first argument(this is where vdot() differs working of dot() method) is used for the calculation of the dot product. It can handle multi-dimensional arrays but working on it as a flattened array.

Parameters –

  1. vector_a : [array_like] if a is complex its complex conjugate is used for the calculation of the dot product.
  2. vector_b : [array_like] if b is complex its complex conjugate is used for the calculation of the dot product.

Return – dot Product of vectors a and b.

Code 1 :




# Python Program illustrating
# numpy.vdot() method
  
import numpy as geek
  
# 1D array
vector_a = 2 + 3j
vector_b = 4 + 5j
  
product = geek.vdot(vector_a, vector_b)
print("Dot Product  : ", product)


Output :

Dot Product  :  (23-2j)

How Code1 works ?
vector_a = 2 + 3j
vector_b = 4 + 5j

As per method, take conjugate of vector_a i.e. 2 – 3j

now dot product = 2(4 – 5j) + 3j(4 – 5j)
= 8 – 10j + 12j + 15
= 23 – 2j

Code 2 :




# Python Program illustrating
# numpy.vdot() method
  
import numpy as geek
  
# 1D array
vector_a = geek.array([[1, 4], [5, 6]])
vector_b = geek.array([[2, 4], [5, 2]])
  
product = geek.vdot(vector_a, vector_b)
print("Dot Product  : ", product)
  
product = geek.vdot(vector_b, vector_a)
print("\nDot Product  : ", product)
  
""" 
How Code 2 works : 
array is being flattened
  
1 * 2 + 4 * 4 + 5 * 5 + 6 * 2 = 55
"""


Output :

Dot Product  :  55

Dot Product  :  55

References :
https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.vdot.html#numpy.vdot

.
This article is contributed by Mohit Gupta_OMG 😀. If you like Lazyroar and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the Lazyroar main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments