How to find lasso beta estimates I'm following this paper https://arxiv.org/pdf/1304.4773.pdf
And for the moment I'm just trying to go through the steps for equation $(1.2)$
$$ \hat \beta_{lasso} = argmin_{\beta} \sum_{i}^{n} (y_{i} - x'_{i} \mathbf\beta)^2 + n\lambda \sum_{j=1}^{p} \left| \beta_{j} \right| $$
In python I thought I could start like so:
import numpy as np

np.random.seed(4)
X = np.array([np.random.normal(size=5) for x in range(6)])
y = np.random.normal(size=6)

ones = [1. for x in range(X.shape[0])]
Xb = np.insert(X, 0, ones, axis=1)
B = np.linalg.inv(np.dot(Xb.T, Xb)).dot(Xb.T).dot(y)
rSquared = (y - np.dot(Xb.T, B))**2
n = 6
lambda_ = 0.01
# not sure what to do at this point
estimate = np.sum(rSquared) +  ( n * lambda_ * np.sum(np.abs(B)))

Could someone help me out in completing this? 
 A: First off, check your rSquared calculation. I think it should be 
(y - np.dot(Xb, B))**2 not (y - np.dot(Xb.T, B))**2.
As I said, a closed form solution is probably not how you want to solve this. Use a minimization routine. Here is one option:
import numpy as np

np.random.seed(4)
X = np.array([np.random.normal(size=5) for x in range(6)])
y = np.random.normal(size=6)

ones = [1. for x in range(X.shape[0])]
Xb = np.insert(X, 0, ones, axis=1)
B = np.linalg.inv(np.dot(Xb.T, Xb)).dot(Xb.T).dot(y)
#rSquared = (y - np.dot(Xb.T, B))**2
n = 6
lambda_ = 0.01
# not sure what to do at this point

# my code starting here

# this is the objective function that sci-kit learn minimizes
# I'm using it here just to show you this method works
def estimate(B):
    return (1./(2*n)) * np.sum((y - np.dot(Xb, B))**2) +  lambda_ * np.sum(np.abs(B))

Then you can do the argmin part:
from scipy.optimize import minimize
res = minimize(estimate, np.ones(6)) # some random starting point

print res['x']
[-0.574803   -0.53032474  1.18149914  0.07927632 -1.22071654 -1.18796359]
print estimate(res['x'])
0.052964866771

And sci-kit:
from sklearn import linear_model
clf = linear_model.Lasso(alpha=lambda_, fit_intercept=False)
clf.fit(Xb,y)

print clf.coef_
[-0.57474883 -0.53025108  1.18070129  0.078776   -1.22018611 -1.18768101]
print estimate(clf.coef_)
0.0529648921815

Pretty close. So now you know this method works (if you trust sci-kit). The only difference between my code and yours, is the estimate function. You'll get slightly different results from sci-kit, but technically it works.
Also, in order to use minimize in this way, you can't calculate your rSquared term outside of the estimate because scipy needs to minimize B for the entire formula together.
