Hi Stack Overflow community,
I have a 3D numpy array Rp
of shape 4x4x701, where each of the 701 4x4 slices represents a certain quantity at a different point in time. I'm trying to efficiently apply a Givens rotation matrix Q
and its Hermitian transpose QH
to each of the 701 slices, and am currently doing it iteratively, like so:
for idx in np.arange(Rp.shape[-1]):
Rp[[j,k],:,idx] = np.dot(Q, Rp[[j,k],:,idx])
Rp[:,[j,k],idx] = np.dot(Rp[:,[j,k],idx], QH)
but there must be a way to do this NOT iteratively (for the numpy speedup). I realise I can just use np.dot
for the first case, but this won't work for the second without some transposition, which seems like it would slow things down.
Any ideas would be greatly appreciated!