【问题标题】:Dot product of a time series of co-ordinates with a time series of rotation matrices时间序列坐标与旋转矩阵时间序列的点积
【发布时间】:2016-12-16 11:49:33
【问题描述】:

我有一个时间序列的航天器坐标,形状为(t,3),还有一个时间序列的旋转矩阵形状为(3,3,t),其中t 是时间序列的长度。我想在每个时间 t 找到坐标的点积与每个时间 t 的旋转矩阵,这样我就得到了一个形状为(t,3) 的数组旋转坐标。

我可以在 for 循环中通过编写来实现这一点:

new_coords = np.zeros_like(input_coords)
for Ci, Vi in enumerate(input_coords):
    new_coords[Ci,:] = np.tensordot(Vi, rotation[:,:,Ci], axes = 1)

如何用一行 Python 替换这个 for 循环?我尝试了np.tensordot 的各种排列,但没有成功。

【问题讨论】:

    标签: python numpy matrix matrix-multiplication dot-product


    【解决方案1】:

    你可以使用np.einsum -

    np.einsum('ijk,ki->kj',rotation, input_coords)
    

    通用格式的形状 -

    rotation     : 3 x 3 x N
    input_coords : N x 3
    

    这里有两个考虑因素 -

    • rotation 的第一个(轴)与 input_coords 的最后一个的总和减少。
    • 保持rotation 的最后一个和input_coords 的第一个对齐。这与嵌套循环中使用Ci 的方式一致。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-17
      • 1970-01-01
      相关资源
      最近更新 更多