# Procrustes in Blender

I am trying to solve the Orthogonal Procrustes problem inside Blender for a specific case but I am having some trouble. I have a face and a pair of glasses in my scene. They are not in a specific position, they can be anywhere. I have then defined the following function using the numpy library, that is an implementation of the Orthogonal procrustes problem:

import numpy as np

def procrustes(X, Y):
X = X - X.mean(axis=0)
Y = Y - Y.mean(axis=0)
(U, S, Vt) = np.linalg.svd(np.dot(Y.T,X))
R = np.dot(U, Vt)
Y = np.array(np.matrix(Y) * np.matrix(R))
return X, Y


It finds the best translation and rotation for putting glasses on the face (it finds an orthogonal matrix which most closely map Y to X) and now I want to apply it. In my case the translation can be avoided and we can assume that it's already fixed. So we can consider only rotation for simplicity. X and Y should be two np arrays of points in the space.
Do you have any idea of how I can apply this function to my problem?

First of all, I would suggest using the letters A and B, instead of X and Y. Furthermore, you don't document what type they are; I assume those are matrices. You can call X.to_euler(...) to get the rotation from the matrix, and assign it to ob.rotation_euler.