title: Adding single column ones to a matrix in NumPy
body: <p>I have a this function that adds column vector of ones to a matrix.</p>
  
  <pre><code>def add_ones(x):
      return np.hstack((np.ones((x.shape[0], 1)), x))
  </code></pre>
  
  <p>when x is a matrix it does it's job fine. For example:</p>
  
  <pre><code>x = np.array([[1, 2], [3, 4]])
  y = np.zeros((5, 5))
  add_ones(x)
  add_ones(y)
  </code></pre>
  
  <p>gives</p>
  
  <pre><code>[[1. 1. 2.]
   [1. 3. 4.]]
  [[1. 0. 0. 0. 0. 0.]
   [1. 0. 0. 0. 0. 0.]
   [1. 0. 0. 0. 0. 0.]
   [1. 0. 0. 0. 0. 0.]
   [1. 0. 0. 0. 0. 0.]]
  </code></pre>
  
  <p>however when I pass it a single vector:</p>
  
  <pre><code>z = np.zeros(5)
  add_ones(z)
  </code></pre>
  
  <p>it gives this error:</p>
  
  <pre><code>ValueError: all the input arrays must have same number of dimensions
  </code></pre>
  
  <p>I'd like it to return </p>
  
  <pre><code>[1. 0. 0. 0. 0. 0.]
  </code></pre>
  
  <p>what should I do?</p>