def regularized_lsq_operator(J, diag):
 J = aslinearoperator(J)
 (m, n) = J.shape
 def matvec(x):
  return np.hstack((J.matvec(x), (diag * x)))
 def rmatvec(x):
  x1 = x[:m]
  x2 = x[m:]
  return (J.rmatvec(x1) + (diag * x2))
 return LinearOperator(((m + n), n), matvec=matvec, rmatvec=rmatvec)

def regularized_lsq_operator ( J , diag ) : J = aslinearoperator ( J ) ( m , n ) = J . shape def matvec ( x ) : return np . hstack ( ( J . matvec ( x ) , ( diag * x ) ) ) def rmatvec ( x ) : x1 = x [ : m ] x2 = x [ m : ] return ( J . rmatvec ( x1 ) + ( diag * x2 ) ) return LinearOperator ( ( ( m + n ) , n ) , matvec = matvec , rmatvec = rmatvec )
return a matrix arising in regularized least squares as linearoperator .