np.allclose(np.array([np.dot(np.dot(vecs[(i), ...], mats[(i), ...]), vecs[(
    i), ...].T) for i in range(N)]), np.einsum('...i,...ij,...j->...', vecs,
    mats, vecs))
Vectorizing multiple vector-matrix multiplications in NumPy