You can replace this if/for with `sh = np.dot(sf, invB.T)`