title: How to fix " operands broadcasting error"
body: <p>I wanted to find gradient of function wrt variable T. I am getting error operand broadcasting. Why I am getting this error and how to fix it? l takes value from 0 to 4. </p>
  
  <pre><code>def grad(l,d1,d2):
        grad_T = 0
        b = 1
        w = np.ones(5,1)
        w.reshape(5,1)
        T = np.random.rand(46,5)
        D = np.random.rand(46,9063)
        if(y[d2]!=y[d1]):
                  difVec = D[ : ,d2].astype(float) - D[ :,d1].astype(float)
                  dify = 1
                  if(y[d2]&lt;y[d1]):
                  dify = -1
                  grad_T = grad_T + (-1*dify*w[l,0]*difVec)/(1+np.exp(dify( 
                  w.transpose() @ T.transpose() @ difVec + b )))
        return(grad_T)
  
      Error
      &lt;ipython-input-40-56571fb637a5&gt; in grad(d1, d2)
      20                 if(y[d2]&lt;y[d1]):
      21                     dify = -1
      ---&gt; 22                     grad_T = grad_T + 
      (-1*dify*w[l,1]*difVec)/(1+np.exp(dify * ( w.transpose() @ 
      T.transpose() @ difVec + b )))
  
     ValueError: operands could not be broadcast together with shapes (46,) 
     (5,)
  </code></pre>