numpy.dot() in Python (original) (raw)

Last Updated : 19 Dec, 2025

numpy.dot() is used to compute the dot product of two arrays.

**Example: This example shows how numpy.dot() calculates the dot product of two 1D arrays.

Python `

import numpy as np

a = np.array([2, 3]) b = np.array([4, 5]) print(np.dot(a, b))

`

**Explanation: np.dot(a, b) -> 2*4 + 3*5 = 8 + 15 = 23.

Syntax

numpy.dot(a, b, out=None)

**Parameters:

Examples

**Example 1: This example demonstrates the dot product of two complex numbers using numpy.dot().

Python `

import numpy as np

a = 2 + 3j b = 4 + 5j print(np.dot(a, b))

`

**Explanation: **np.dot(a, b) multiplies using complex arithmetic -> 2*(4+5j) + 3j*(4+5j) -> -7 + 22j.

**Example 2: This example shows matrix multiplication using numpy.dot() on two 2D arrays.

Python `

import numpy as np

a = np.array([[1, 4], [5, 6]])

b = np.array([[2, 4], [5, 2]])

print(np.dot(a, b))

`

**Explanation: np.dot(a, b) performs matrix multiplication

**Example 3: This example uses numpy.dot() with a 2D array and a 1D array to produce a vector.

Python `

import numpy as np

a = np.array([[3, 5], [1, 2], [4, 1]])

b = np.array([2, 3])

print(np.dot(a, b))

`

**Explanation: Each row of a is dotted with vector b