Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Numpy: multiply, matmul, dot for vectors

  • multiply

  • matmul

  • dot

  • multiply Multiply arguments element-wise.

  • matmul Matrix product of two arrays.

  • dot Dot product of two arrays.

import numpy as np

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

c = np.multiply(a, b)
print(c) # [18 20 14]

d = np.dot(a, b)
print(d)   # 52

m = np.matmul(a, b)
print(m)   # 52