Solution (source code)

= Solution

The objective separates by coordinates, so minimize
$$
h_i(z)=\frac12(z-x_i)^2+\lambda|z|.
$$
The <subgradient optimality condition> is
$$
0\in z-x_i+\lambda\,\partial|z|.
$$
For $z>0$ this gives $z=x_i-\lambda$, valid when $x_i>\lambda$; for $z<0$ it gives $z=x_i+\lambda$, valid when $x_i<-\lambda$. At $z=0$, the condition is $x_i\in[-\lambda,\lambda]$. Therefore the shrinkage operator is the <soft-thresholding operator>
$$
[\psi_\lambda(x)]_i
=\begin{cases}
x_i-\lambda,&x_i>\lambda,\\
0,&-\lambda\leq x_i\leq\lambda,\\
x_i+\lambda,&x_i<-\lambda.
\end{cases}
$$