Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
NumPy | Vector Multiplication
Next article icon

Thenumpy.ndarray.dot()function computes thedot product of two arrays. It is widely used inlinear algebra,machine learning anddeep learning for operations likematrix multiplication andvector projections.

Example:

Python
importnumpyasnpa=np.array([1,2,3])b=np.array([4,5,6])result=np.dot(a,b)print(result)

Output
32

Understanding the Dot Product

  • Ifboth inputs are 1D arrays,dot() computes theinner product, resulting in a scalar.
  • Ifeither input is an N-dimensional array,dot() performsmatrix multiplication.
  • Ifone input is a scalar,dot() performselement-wise multiplication.
Syntax : numpy.ndarray.dot(arr, out=None)

Parameters:

  • arr(array_like): The input array for the dot product.
  • out(ndarray, optional): Output argument (stores the result).

Returns:

  • Ascalar,vector ormatrix depending on input shape.

Code Implementation

Code #1 : Usingnumpy.ndarray.dot() for Matrix Multiplication

Python
importnumpyasgeekarr1=geek.eye(3)arr=geek.ones((3,3))*3gfg=arr1.dot(arr)print(gfg)

Output
[[3. 3. 3.] [3. 3. 3.] [3. 3. 3.]]

Code #2 : Performing Multiple Dot Products

Python
importnumpyasgeekarr1=geek.eye(3)arr=geek.ones((3,3))*3gfg=arr1.dot(arr).dot(arr)print(gfg)

Output
[[27. 27. 27.] [27. 27. 27.] [27. 27. 27.]]

In this article, we explored thenumpy.ndarray.dot() function, which computes the dot product of two arrays. We demonstrated its application using identity matrices and uniform arrays, highlighting its significance in matrix operations and numerical computing.


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