In practice, we often do not know the precise quantum-mechanical state of the system, but have some statistical knowledge about the probabilities for the system being in one of a set of states (note that these probabilities are completely distinct from the probabilities which arise when a measurement is made). For a fuller discussion of what follows, see [130].
Suppose that there is a set of orthonormal states $\{| \psi_i \rangle\}$ for our system, and that the probabilities that the system is in each of these states are $\{ w_i \}$. The expectation value of an observable $O$ is
$$\begin{equation} \langle O \rangle_{\mathrm{stat}} = \sum_i w_i \langle \psi_i | {\hat O} | \psi_i \rangle \end{equation}$$
which is a quantum and statistical average.
We define the density-operator as
$$ \begin{equation} {\hat \rho} = \sum_i w_i | \psi_i \rangle \langle \psi_i | \end{equation} $$
and introduce a complete set of basis states $\{ | \phi_i \rangle \}$ as linear combinations:
$$ \begin{equation} | \psi_i \rangle = \sum_j c_j^{(i)} | \phi_j \rangle . \end{equation} $$
Expressed in terms of this basis, the expectation value becomes
$$ \begin{eqnarray} \langle O \rangle_{\mathrm{stat}} &=& \sum_i w_i \sum_j {c_j^{(i)}}^{\ast} \langle \phi_j | {\hat O} \sum_k c_k^{(i)} | \phi_k \rangle \nonumber \\ &=& \sum_j \sum_k \left[ \sum_i {c_j^{(i)}}^{\ast} w_i c_k^{(i)} \right] \langle \phi_j | {\hat O} | \phi_k \rangle \nonumber \\ &=& \sum_j \sum_k \rho_{kj} O_{jk} = {\rm Tr}(\rho O) \end{eqnarray} $$
in which the density-matrix $ \rho_{kj} $, the matrix representation of the density-operator in this basis, is defined by
$$ \begin{equation} \rho_{kj}= \sum_i {c_j^{(i)}}^{\ast} w_i c_k^{(i)} = \langle \phi_k | {\hat \rho} | \phi_j \rangle \end{equation} $$
The fact that the probabilities must sum to unity is expressed by the fact that the trace of the density-matrix is also unity i.e. ${\rm Tr}(\rho) = 1$ . A state of the system which corresponds to a single state-vector (i.e. when $w_i = 1$ and $w_j = 0 ~~ \forall~ j \not= i$ ) is known as a pure state and for such a state the density-matrix obeys a condition known as idempotency i.e. $\rho^2 = \rho$ which is only obeyed by matrices whose eigenvalues are all zero or unity. The more general state introduced above is known as a mixed state and does not obey the idempotency condition. Other properties of the density-matrix are that it is Hermitian, and that in all representations the diagonal elements are always real and lie in the interval $[0,1]$