I have two matrices:
target = np.array([[1, 1, 1, 1, 1],
[2, 2, 2, 2, 2],
[3, 3, 3, 3, 3]])
source = np.array([[11, 11, 11, 11, 11],
[22, 22, 22, 22, 22],
[33, 33, 33, 33, 33]])
and I want to create a transformation matrix to project the source matrix to the target one.
I found that Scipy library provides a function to do it:
from scipy.spatial import procrustes
mtx1, mtx2, disparity = procrustes(target, source)
based on the documentation, it says that:
Thus, mtx2
is the projected matrix.
What if I have another data and I want to project them to the target matrix using the "learned transformation matrix" that Scipy used to project the source matrix to the target one?
How can I do it using Scipy?
You need to modify the function in order to return the transformation matrix (
R
).The source code after removing the comments looks like:
Source: https://github.com/scipy/scipy/blob/v1.3.0/scipy/spatial/_procrustes.py#L17-L132