It might be helpful to read about
Dyadic notation.
That Wikipedia article doesn't mention it, but the same idea can be written using Dirac notation for outer products. If
##
\{ |1 \rangle, \ldots, | N \rangle \}
##
is an orthonormal basis for an ##N## dimensional space, then any linear operator on that space can be written
##
\quad a_{11} | 1 \rangle \langle 1 | + a_{12} | 1 \rangle \langle 2 | + \cdots + a_{1N} | 1 \rangle \langle N |
##
##
+ a_{21} | 2 \rangle \langle 1 | + a_{22} | 2 \rangle \langle 2 | + \cdots + a_{2N} | 2 \rangle \langle N |
##
##
+ \cdots
##
##
+ a_{N1} | N \rangle \langle 1 | + a_{N2} | N \rangle \langle 2 | + \cdots + a_{NN} | N \rangle \langle N |
##
In the given basis, this is the operator represented by the matrix
##
A =
\left[\begin{array}{cccc}
a_{11} & a_{12} & \cdots & a_{1N} \\
a_{21} & a_{22} & \cdots & a_{2N} \\
\cdots \\
a_{N1} & a_{N2} & \cdots & a_{NN} \\
\end{array}\right]
##