我怀疑这可能不是一个很好的问题,但我已经完全触礁了,需要一些帮助。在
我正在尝试实现以下代码:
http://www.nathanieltroutman.net/content/calculating-minimum-volume-bounding-box
在C#中,原始的在Python中。在
在我进入这一部分之前,一切都很顺利:
def calcProjections(points, *vectors):
"""Calculates the projection of points (NxD) onto the vectors
(MxD) and return the projections p which is a matrix sized (N, M)
where N is the number of points and M is the number of vectors.
p[i][j], is the projection of points[i] onto vectors[j] (which is
between 0 and 1)."""
u = np.array(vectors)
# project the points onto the vectors into on fell swoop
d = np.dot(points, u.T)
# this is the dot product of each vector with itself
v2 = np.diag(np.inner(u, u))
p = d / v2
return p
我只是在努力解释到底发生了什么。我不知道作者通过投影到特定的向量上是什么意思,也不知道输出的格式(该死的鸭子打字)。这个描述对我来说也有点太模糊了。在
有人对这件事有什么建议或解释吗?非常感谢任何帮助。在
谢谢。在
下面是一个在交互式Ipython shell中完成的计算示例:
如函数doc中指定的,输入是
(4,3)
points
,vectors
一个2(3,)
向量的列表,输出是(4,2)
数组,p
。在d
是4x3矩阵与2x3(或转置后,3x2)数组的矩阵(点)乘积,结果是4x2。v2
也可以计算为np.sum(u,u, axis=1)
,即两个向量的大小。p
只是v2
规范化的点积。在如果您熟悉爱因斯坦求和符号(在物理学中使用),计算也可以表示为:
^{pr2}$相关问题 更多 >
编程相关推荐