Gavin Pai
Gavin Pai

Reputation: 3

NumPy Dot Product Matrices

Is there a NumPy matrix/vector function that does,

         [x1*y1]
         [x2*y2]
x*y  =   [x3*y3]
         [-----]
         [xn*yn]

Upvotes: 0

Views: 86

Answers (2)

Charles Harris
Charles Harris

Reputation: 984

It is best to use arrays instead of matrices, matrices will go away some day. A matrix multiplication operator, @, can be used with arrays in recent versions of NumPy when you use Python 3.5+. Having a matrix multiplication operator was pretty much the only reason for matrices.

Upvotes: 0

Javier Lim
Javier Lim

Reputation: 148

There is no method, just use *

For example, consider

import numpy as np
a = np.array([[0, 1, 2, 3, 4],
           [5, 6, 7, 8, 9]])

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

print(a * b)

This code returns

[[ 0  2  4  6  8]
 [10 12 14 16 18]]

Upvotes: 1

Related Questions