title: Householder Reflection of a vector
body: <p>I want to construct a Householder reflection of a vector. My attempt is below according to the algorithm.</p>
  
  <pre><code>import math
  import numpy as np
  def vector_norm(n , vec):
      result = 0
      for k in range (n ):
         result = result + vec[k] * vec[k]
      return math.sqrt(result)
  
  def householder(vec):
      #vec the vector to be transformed
      vec = np.asarray(vec, dtype=float)
      if vec.ndim != 1:
           raise ValueError("vec.ndim = %s, expected 1" % vec.ndim)
  
      n = len(vec)
      I = np.eye(n)
      e1 = np.asarray(([0.0]*n),dtype=float)
      e1[0] = 1.0
      V1 = vec - vector_norm(n , vec)*e1
      V_trans = np.array([V1])
      H = I - 2 * ((V_trans.T @ V_trans) / vector_norm( n ,V1))
      return V1 , H
  </code></pre>
  
  <p>However, when I check;</p>
  
  <pre><code>v = np.array([1, 2, 3])
  v1, h = householder(v)
  assert_allclose(np.dot(h, v1), v)
  assert_allclose(np.dot(h, v), v1)
  </code></pre>
  
  <p>The result is wrong.</p>
  
  <pre><code>AssertionError: 
  Not equal to tolerance rtol=1e-07, atol=0
  
  (mismatch 100.0%)
  x: array([ 22.095208, -16.118139, -24.177209])
  y: array([1, 2, 3])
  </code></pre>