.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.