If $(X,|\cdot|)$ is a Hilbert space and $Z$ is a random vector in $X$ with $E|Z|^2<\infty$, then $EZ$ is the unique minimizer of $E|Z-a|^2$ in $a\in X$.

So, more generally, for any random element $Z$ of any metric space $(X,d)$ with $Ed(Z,a)^2<\infty$ for some (or, equivalenly, for all) $a\in X$, one may define an expectation of $Z$ as any minimizer of $Ed(Z,a)^2$ in $a\in X$ (if such a minimizer exists). In general, such a minimizer does not have to be unique.

For any $p\in[1,\infty]$, one can similarly define a $(p-1)$-expectation of $Z$ as any minimizer of $\|d(Z,a)\|_p$ in $a\in X$, where for any real-valued random variable $\xi$ we let $\|\xi\|_p:=(E|\xi|^p)^{1/p}$ if $p\in[1,\infty)$ and $\|\xi\|_\infty:=\lim_{p\to\infty}\|\xi\|_p$.

Then a $1$-expectation is an expectation defined above,
and a $0$-expectation is a geometric median, and an $\infty$-expectation is a generalized midrange.