solving least square I know and understand that $\ Ax = B $ is solved by $\ x= A^{-1}B $
and this can be written in python as 
np.linalg.solve(A,B) 

However I am unsure how to solve: 
$\ \frac12 ||Gx -d||^2 + \frac a2 ||x||^2  $
I need to find a way to transform it into $\ Ax = B $
I thought of doing :
$\ \frac12  (Gx -d)(Gx -d)^t + \frac a2 xx^t  $
$\ \frac12 ( Gx -d)(G^tx^t - d^t) + \frac a2 xx^t  $
but not sure how to carry on
Please note that G is a matrix , x and d are vectors and a is a constant
 A: To find the minimum, you need to consider 
$$\frac{d}{dx} (\frac12 ||Gx -d||^2 + \frac a2 ||x||^2) = 0.$$
This should give you a linear system $Ax = B$
A: The thing is you can not put it in a form of $$\Vert Ax - b \Vert^2$$ unless your $a = 0$, then $A = G$ and $b = d$.  To find the minimum and as @Pebeto mentions, you need to compute the derivative wrt $x$.
A: When we have a minimum at $\mathbf x$, all the partial derivatives must be zero.
Let's start with $x_1$ and let's assume we minimize only $\|G\mathbf x -\mathbf d\|^2$. Then:
\begin{align}\frac\partial{\partial x_1}\Bigg[\|G\mathbf x -\mathbf d\|^2\Bigg]
&=\frac\partial{\partial x_1}\Bigg[(G\mathbf x -\mathbf d)^t(G\mathbf x -\mathbf d)  \Bigg] \\
&=\left(G\frac\partial{\partial x_1}\mathbf x\right)^t(G\mathbf x -\mathbf d)
+(G\mathbf x -\mathbf d)^t\left(G\frac\partial{\partial x_1}\mathbf x\right) \\
&= (G\mathbf e_1)^t(G\mathbf x -\mathbf d)
+(G\mathbf x -\mathbf d)^t(G\mathbf e_1) = 0
\end{align}
Note that $(G\mathbf e_1)^t(G\mathbf x -\mathbf d)$ is a scalar. Therefore it is equal to its transpose $((G\mathbf e_1)^t(G\mathbf x -\mathbf d))^t = (G\mathbf x -\mathbf d)^t(G\mathbf e_1)$.
So:
$$\frac\partial{\partial x_1}\Bigg[\|G\mathbf x -\mathbf d\|^2\Bigg]
= 2(G\mathbf e_1)^t(G\mathbf x -\mathbf d) = 0
$$
Furthermore, $G\mathbf e_1$ is the first column vector in $G$, and $(G\mathbf e_1)^t$ is that same column vector written as a row. As the equation must not only be true for $\mathbf e_1$, but for every standard unit vector, we can write it as the set of equations:
$$2(G)^t(G\mathbf x -\mathbf d) = \mathbf 0$$
When we apply the same method to your original expression $\frac12 \|G\mathbf x - \mathbf d\|^2 + \frac a2 \|\mathbf x\|^2$, we get:
$$G^t(G\mathbf x - \mathbf d) + a \mathbf x = \mathbf 0$$
Rewrite to get:
$$(G^t G + aI)\mathbf x = G^t\mathbf d$$
as desired.
