I have $\boldsymbol x_i$ which is a $(p+1) \times 1$ matrix (a column vector).
Also $\boldsymbol X=(\boldsymbol x_1^T, \cdots , \boldsymbol x_n^T)^T$ is a $n \times (p+1)$ matrix (a column vector whose elements are row vectors).
Imagine I create the following matrix $\boldsymbol H =\boldsymbol{X(X^TX)^{-1}X^T}$
How do I find the $(ij)^{th}$ element of this matrix?
My book says, without any explanation, that it is very easy to see that $[\boldsymbol H]_{ij}=\boldsymbol{x_i^T(X^TX)^{-1}x_j^T}$
How is this even something easy to see? There must be an intuition behind it. This is just one example, but in general throughout the whole book, it seems very easy to find elements of such matrices. Is there a trick or intuition?
Suppose we have an $n-$by$-m$ matrix $H$ and a column $m$-vector $v=([v]_1,[v]_2,\cdots,[v]_m)^T$. Then the matrix multiplication $Hv$ is a column $n$-vector; more precisely, if we write $H$ in terms of its column vectors $\{h_k\}$ we have
$$Hv=(h_1\, h_2\,\cdots \, h_m)\begin{pmatrix} [v]_1 \\ [v]_2 \\ \vdots \\ [v]_m \end{pmatrix}=h_1 [v]_1+h_2 [v]_2+\cdots +h_m [v]_m$$ i.e. $Hv$ is a linear combination of the columns of $H$. In particular, if $v=e_j$ we have $He_j=h_i=([H]_{1j},[H]_{2j},\cdots, [H]_{nj})^T$. If we wanted to instead get a linear combination of rows, we should multiply on the left e.g. we have $e_i^T H=([H]_{i1},[H]_{i2},\cdots,[H]_{in})$ as the $i$th row of $H$. Combining these gives $e_i^T H e_j = [H]_{ij}$ as the desired matrix element, and for the case of interest $$[H]_{ij}=e_i^T X (X^T X)^{-1} X^T e_j=x_i^T (X^T X)^{-1} x_j$$ in agreement with the text.