[英]Taking the dot product of a np.ndarray in Python
I am trying to find the value of the dot product of x, which is 1.17794933^2 + (-0.07446217)^2 = 1.3931.我试图找到 x 的点积值,即 1.17794933^2 + (-0.07446217)^2 = 1.3931。 I tried x.dot(x)
but that did not seem to work.我试过x.dot(x)
但这似乎不起作用。 Is there another way to perform dot product when x
is of type numpy.ndarray
?当x
是numpy.ndarray
类型时,是否有另一种方法来执行点积?
For your desired output, You may try einsum
对于您想要的输出,您可以尝试einsum
In [1254]: np.einsum('ij,ij',x,x)
Out[1254]: 1.3931092388085575
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.