Calculate Dot Product of Two Vectors in Numpy for Beginners – Numpy Tutorial

By | September 15, 2019

Dot product of two vectors is defined as:

In this tutorial, we will write an example to show how to compute dot product of two vectors in numpy.

Preliminaries

import numpy as np

Create two vectors

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

Calculate the dot product of this two vector

d = np.dot(v1, v2)

The output is:

40

We shoud use np.dot() function to calculate, however, we can not use * operation

d2 = v1 * v2

The output is:

array([ 2,  6, 12, 20])

which is Hadamard Product of this two vector.