title: non-broadcastable output operand with shape (30,1) doesn't match the broadcast shape (30,30)
body: <p>implement a new function to calculate the new objective function and gradients</p>
  <p>Got following error
  for the Stochastic Gradient descent.
  I don't know what seems to be the problem
  as my matrix is already 30 by 1</p>
  <pre><code>def stochastic_objective_gradient(w, xi, yi, lam):
      d = xi.shape[0]
      yx = yi * xi # 1-by-d matrix
      yxw = float(numpy.dot(yx, w)) # scalar
      
      # calculate objective function Q_i
      loss = numpy.log(1 + numpy.exp(-yxw)) # scalar
      reg = lam / 2 * numpy.sum(w * w) # scalar
      obj = loss + reg
      
      # calculate stochastic gradient
      g_loss = -yx.T / (1 + numpy.exp(yxw)) # d-by-1 matrix
      g = g_loss + lam * w # d-by-1 matrix
      
      return obj, g
  
  def sgd(x, y, lam, stepsize, max_epoch=100, w=None):
      n, d = x.shape
      objvals = numpy.zeros(max_epoch) # store the objective values
      if w is None:
          w = numpy.zeros((d, 1)) # zero initialization
      
      for t in range(max_epoch):
          # randomly shuffle the samples
          rand_indices = numpy.random.permutation(n)
          x_rand = x[rand_indices, :]
          y_rand = y[rand_indices, :]
          
          objval = 0 # accumulate the objective values
          for i in range(n):
              xi = x_rand[i, :] # 1-by-d matrix
              yi = float(y_rand[i, :]) # scalar
              obj, g = stochastic_objective_gradient(w, xi, yi, lam)
              objval += obj
              w -= stepsize * g
          
          stepsize *= 0.9 # decrease step size
          objval /= n
          objvals[t] = objval
          print('Objective value at epoch t=' + str(t) + ' is ' + str(objval))
      
      return w, objvals
  
  </code></pre>
  <p>What can be done to match the shape?</p>
  <pre><code>    ```
      ---------------------------------------------------------------------------
      ValueError                                Traceback (most recent call last)
      &lt;ipython-input-195-06f44b846812&gt; in &lt;module&gt;()
            3 lam = 0
            4 stepsize = 0.1
      ----&gt; 5 w, objvals_sgd = sgd(x_train, y_train, lam, stepsize)
      
      &lt;ipython-input-79-54d9a7949c9d&gt; in sgd(x, y, lam, stepsize, max_epoch, w)
           33             obj, g = stochastic_objective_gradient(w, xi, yi, lam)
           34             objval += obj
      ---&gt; 35             w -= stepsize * g
           36 
           37         stepsize *= 0.9 # decrease step size
      
      ValueError: non-broadcastable output operand with shape (30,1) doesn't match the broadcast shape (30,30)
      ```
  </code></pre>