The easiest implementation (with Numpy in Python>=3.6) of Markley's solution would be:
import numpy as npdef q_average(Q, W=None): if W is not None: Q *= W[:, None] eigvals, eigvecs = np.linalg.eig(Q.T@Q) return eigvecs[:, eigvals.argmax()]
where Q
is of size N-by-4. The resulting quaternion is already normalized.
In this case the weights are equal to 1 by default. Otherwise you can give a list of weights of size N (one per quaternion.)
That's it.