Numpy ndarray.dot() function | Python (original) (raw)

Last Updated : 07 Apr, 2025

The **numpy.ndarray.dot()*function computes the dot product of two arrays. It is widely used in **linear algebra,* **machine learning and **deep learning for operations like **matrix multiplication and **vector projections.

**Example:

Python `

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

`

**Understanding the Dot Product

**Syntax : numpy.ndarray.dot(arr, out=None)

**Parameters:

**Returns:

Code Implementation

**Code #1 : Using numpy.ndarray.dot() for Matrix Multiplication

Python `

import numpy as geek arr1 = geek.eye(3) arr = geek.ones((3, 3)) * 3 gfg = arr1.dot(arr) print(gfg)

`

Output

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

**Code #2 : Performing Multiple Dot Products

Python `

import numpy as geek arr1 = geek.eye(3) arr = geek.ones((3, 3)) * 3 gfg = arr1.dot(arr).dot(arr) print(gfg)

`

Output

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

In this article, we explored the numpy.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.