title: operands could not be broadcast together with shapes (100,2) (100,100)
body: <p>I was making neural network model using some of IMDB data. I created bag of words and split data into train_data and test_data. X_train is data to be trained for the model, and T_train is the label for them. I copied and pasted definitions of functions from the book I am studying and defined network model. </p>
  
  <pre><code># coding: utf-8
  import sys, os
  sys.path.append(os.pardir)
  
  X_train = np.array([np.array(xi) for xi in x_train])
  T_train = np.array([np.array(ti) for ti in t_train])
  
  network = TwoLayerNet(input_size=max_length, hidden_size=100 , output_size=2)
  
  iters_num = 10000
  train_size = X_train.shape[0]
  batch_size = 100
  learning_rate = 0.1
  
  train_loss_list = []
  train_acc_list = []
  test_acc_list = []
  
  iter_per_epoch = max(train_size / batch_size, 1)
  
  for i in range(iters_num):
      batch_mask = np.random.choice(train_size, batch_size)
      x_batch = X_train[batch_mask]
      t_batch = T_train[batch_mask]
  
      #grad = network.numerical_gradient(x_batch, t_batch)
      grad = network.gradient(x_batch, t_batch)
  
      for key in ('W1', 'b1', 'W2', 'b2'):
          network.params[key] -= learning_rate * grad[key]
  
      loss = network.loss(x_batch, t_batch)
      train_loss_list.append(loss)
  
      if i % iter_per_epoch == 0:
          train_acc = network.accuracy(X_train, T_train)
          test_acc = network.accuracy(x_test, t_test)
          train_acc_list.append(train_acc)
          test_acc_list.append(test_acc)
          print(train_acc, test_acc)
  </code></pre>
  
  <p>And I end up with the error below:</p>
  
  <pre><code>ValueError                                Traceback (most recent call last)
  &lt;ipython-input-25-cce2ada4f4f7&gt; in &lt;module&gt;
       37     
       38     #grad = network.numerical_gradient(x_batch, t_batch) 
  ---&gt; 39     grad = network.gradient(x_batch, t_batch)
       40 
       41     
  
  &lt;ipython-input-14-52e9d162e44b&gt; in gradient(self, x, t)
       53     def gradient(self, x, t):
       54         # forward
  ---&gt; 55         self.loss(x, t)
       56 
       57         # backward
  
  &lt;ipython-input-14-52e9d162e44b&gt; in loss(self, x, t)
       28     def loss(self, x, t):
       29         y = self.predict(x)
  ---&gt; 30         return self.lastLayer.forward(y, t)
       31 
       32 
  
  &lt;ipython-input-14-52e9d162e44b&gt; in forward(self, x, t)
      146         self.t = t
      147         self.y = softmax(x)
  --&gt; 148         self.loss = cross_entropy_error(self.y, self.t)
      149 
      150         return self.loss
  
  &lt;ipython-input-14-52e9d162e44b&gt; in cross_entropy_error(y, t)
      172 
      173     batch_size = y.shape[0]
  --&gt; 174     return -np.sum(t * np.log(y + 1e-7)) / batch_size
      175     #return -np.sum(np.dot(np.log(y + 1e-7), t)) / batch_size
      176     #return -np.sum(np.log(y[np.arange(batch_size), t] + 1e-7)) / batch_size
  
  ValueError: operands could not be broadcast together with shapes (100,2) (100,100) 
  </code></pre>
  
  <p>I'm not even sure from where the shape (100, 100) came from..
  Glad if someone would help.</p>