繁体   English   中英

如何计算多个点的仿射变换?

[英]How to compute an affine transformation of multiple points?

我有一个点(484,3,1)的3d numpy数组和一个2d转换矩阵(3,3)。 我想计算所有484点的转换。

我试图重塑数组并计算点积,但是我很难使它输出一个(484,3,1)形状的数组,其中所有点都进行了转换。

points = np.random.randint(0, 979, (484,3,1)) 
transformation = array([[0.94117647, 0.        , 0.        ],
                        [0.        , 0.94117647, 0.        ],
                        [0.        , 0.        , 1.        ]])

points.shape = (484,3,1)
transformation = (3,3)

transformation.dot(points).shape = (3,484,1)

我希望这是尽可能优化的。 任何建议将不胜感激。

只是做一个重塑到(484,3)的尺寸和使用np.matmulnp.dot也是可能的,但因为你正在寻找一个矩阵乘法matmul是首选根据文档 )产品

np.matmul(points.reshape(484,-1), transformation).reshape(484,3,-1)

最终的形状与最后一次重塑所给出的形状相同: (484,3,1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM