使用python计算向量投影 [英] using python to calculate Vector Projection

查看:1006
本文介绍了使用python计算向量投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有更简单的命令来计算矢量投影? 我改为使用以下内容:

Is there an easier command to compute vector projection? I am instead using the following:

x = np.array([ 3, -4,  0])
y = np.array([10,  5, -6])
z=float(np.dot(x, y))
z1=float(np.dot(x, x))
z2=np.sqrt(z1)
z3=(z/z2**2)
x*z3

推荐答案

也许这就是您真正想要的:

Maybe this is what you really want:

np.dot(x, y) / np.linalg.norm(y)

这应该使向量x投影到向量y上-参见 https://en .wikipedia.org/wiki/Vector_projection .另外,如果要计算yx上的投影,则在上式的分母(norm)中用x替换y.

This should give the projection of vector x onto vector y - see https://en.wikipedia.org/wiki/Vector_projection. Alternatively, if you want to compute the projection of y onto x, then replace y with x in the denominator (norm) of the above equation.

正如@VaidAbhishek所评论的那样,以上公式用于 scalar 投影.为了获得 vector 投影,将标量投影乘以单位矢量,然后在投影第一矢量的方向上将其乘以单位矢量.然后可以将该公式修改为:

As @VaidAbhishek commented, the above formula is for the scalar projection. To obtain vector projection multiply scalar projection by a unit vector in the direction of the vector onto which the first vector is projected. The formula then can be modified as:

y * np.dot(x, y) / np.dot(y, y)

,用于xy上的矢量投影.

for the vector projection of x onto y.

这篇关于使用python计算向量投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆