Fast tensor rotation with NumPy
To use tensordot, compute the outer product of the g tensors: def rotT(T, g): gg = np.outer(g, g) gggg = np.outer(gg, gg).reshape(4 * g.shape) axes = ((0, 2, 4, 6), (0, 1, 2, 3)) return np.tensordot(gggg, T, axes) On my system, this is around seven times faster than Sven’s solution. If the g tensor doesn’t … Read more