.dot()
Anonymous contributor
Published May 10, 2024
Contribute to Docs
In NumPy, the .dot()
method computes the dot product of two arrays. For 1-D arrays, it provides a scalar value. When both arrays are 2-D, it performs matrix multiplication, resulting in a new 2-D array. Further details about various scenarios, including arrays with more than two dimensions, can be found in the NumPy .dot()
documentation. This method is widely utilized in linear algebra and numerical computations.
Syntax
numpy.dot(a, b, out=None)
a
: The first array, which could be 1-D, 2-D, or higher dimensional.b
: The second array, having compatible dimensions witha
, and also could be 1-D, 2-D, or higher dimensional.out
: Optional parameter that specifies the output array where the result is stored. If not provided, a new array is created.
Example
The usage of the .dot()
method is demonstrated in the following example:
import numpy as np# Define two arraysarray_a = [3,4,5]array_b = [1,2,3]# Compute the dot product and print the resultprint(np.dot(array_a, array_b))
The above code will produce the following output:
26
Codebyte Example
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:NumPy on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Skill path
Data Science Foundations
Learn to clean, analyze, and visualize data with Python and SQL.Includes 15 CoursesWith CertificateBeginner Friendly55 hours - Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly90 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours