Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
numpy.fromstring() function – Python
Next article icon

numpy.dot(vector_a, vector_b, out = None) returns the dot product of vectors a and b. It can handle 2D arrays but considers them as matrix and will perform matrix multiplication. For N dimensions it is a sum-product over the last axis of a and the second-to-last of b :

dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])  

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. 
  3. out :[array, optional] output argument must be C-contiguous, and its dtype must be the dtype that would be returned for dot(a,b). 

Dot Product of vectors a and b. if vector_a and vector_b are 1D, then scalar is returned

Code 1:

Python
# Python Program illustrating# numpy.dot() methodimportnumpyasgeek# Scalarsproduct=geek.dot(5,4)print("Dot Product of scalar values  : ",product)# 1D arrayvector_a=2+3jvector_b=4+5jproduct=geek.dot(vector_a,vector_b)print("Dot Product  : ",product)

Output:

Dot Product of scalar values  :  20Dot Product  :  (-7+22j)
How Code1 works ? vector_a = 2 + 3j vector_b = 4 + 5jnow dot product = 2(4 + 5j) + 3j(4 +5j) = 8 + 10j + 12j - 15 = -7 + 22j

Code 2:

Python
# Python Program illustrating# numpy.dot() methodimportnumpyasgeek# 1D arrayvector_a=geek.array([[1,4],[5,6]])vector_b=geek.array([[2,4],[5,2]])product=geek.dot(vector_a,vector_b)print("Dot Product  :\n",product)product=geek.dot(vector_b,vector_a)print("\nDot Product  :\n",product)"""Code 2 : as normal matrix multiplication"""

Output:

Dot Product  :  [[22 12] [40 32]]Dot Product  :  [[22 32] [15 32]]

 


M

Mohit Gupta
Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp