Adrian
Adrian

Reputation: 9793

Taking the dot product of a np.ndarray in Python

enter image description here

I am trying to find the value of the dot product of x, which is 1.17794933^2 + (-0.07446217)^2 = 1.3931. I tried x.dot(x) but that did not seem to work. Is there another way to perform dot product when x is of type numpy.ndarray?

Upvotes: 1

Views: 37

Answers (1)

Andy L.
Andy L.

Reputation: 25239

For your desired output, You may try einsum

In [1254]: np.einsum('ij,ij',x,x)
Out[1254]: 1.3931092388085575

Upvotes: 1

Related Questions