Numpy inner product of 2 column vectors

Viewed 8737

How can I take an inner product of 2 column vectors in python's numpy

Below code does not work

import numpy as np
x = np.array([[1], [2]])
np.inner(x, x)

It returned

array([[1, 2],
       [2, 4]])`

instead of 5

4 Answers

Try the following it will work

np.dot(np.transpose(a),a))

make sure col_vector has shape (N,1) where N is the number of elements

then simply sum one to one multiplication result

np.sum(col_vector*col_vector)

Related