title: Theano multiple tensors as output
body: <p>I am using Theano to create a neural network, but when I try to <strong>return two lists of tensors at the same time in a list</strong> I get the error:</p>
  
  <pre><code>#This is the line that causes the error
  #type(nabla_w) == &lt;type 'list'&gt;
  #type(nabla_w[0]) == &lt;class 'theano.tensor.var.TensorVariable'&gt;
  backpropagate = function(func_inputs, [nabla_w, nabla_b])
  
  TypeError: Outputs must be theano Variable or Out instances. Received [dot.0, dot.0, dot.0, dot.0] of type &lt;type 'list'&gt;
  </code></pre>
  
  <p>What kind of Theano structure should I use to return the two tensors together in an array so I can retrieve them like this:</p>
  
  <pre><code>nabla_w, nabla_b = backpropagate(*args)
  </code></pre>
  
  <p>I tried using some of the things I found in the <a href="http://deeplearning.net/software/theano/library/tensor/basic.html" rel="nofollow">basic Tensor functionality page</a> but none of those work. (For example I tried the stack or stacklists)</p>
  
  <p>Here is the error I get using theano.tensor.stack or stacklists:</p>
  
  <pre><code>ValueError: all the input array dimensions except for the concatenation axis must match exactly
  Apply node that caused the error: Join(TensorConstant{0}, Rebroadcast{0}.0, Rebroadcast{0}.0, Rebroadcast{0}.0, Rebroadcast{0}.0)
  Inputs shapes: [(), (1, 10, 50), (1, 50, 100), (1, 100, 200), (1, 200, 784)]
  Inputs strides: [(), (4000, 400, 8), (40000, 800, 8), (160000, 1600, 8), (1254400, 6272, 8)]
  Inputs types: [TensorType(int8, scalar), TensorType(float64, 3D), TensorType(float64, 3D), TensorType(float64, 3D), TensorType(float64, 3D)]
  Use the Theano flag 'exception_verbosity=high' for a debugprint of this apply node.
  </code></pre>
  
  <p>A little extra context to the code:</p>
  
  <pre><code>weights = [T.dmatrix('w'+str(x)) for x in range(0, len(self.weights))]
  biases = [T.dmatrix('b'+str(x)) for x in range(0, len(self.biases))]
  nabla_b = []
  nabla_w = []
  # feedforward
  x = T.dmatrix('x')
  y = T.dmatrix('y')
  activations = []
  inputs = []
  activations.append(x)
  for i in xrange(0, self.num_layers-1):
      inputt = T.dot(weights[i], activations[i])+biases[i]
      activation = 1 / (1 + T.exp(-inputt))
      activations.append(activation)
      inputs.append(inputt)
  
  delta = activations[-1]-y
  nabla_b.append(delta)
  nabla_w.append(T.dot(delta, T.transpose(inputs[-2])))
  
  for l in xrange(2, self.num_layers):
      z = inputs[-l]
      spv = (1 / (1 + T.exp(-z))*(1 - (1 / (1 + T.exp(-z)))))
      delta = T.dot(T.transpose(weights[-l+1]), delta) * spv
      nabla_b.append(delta)
      nabla_w.append(T.dot(delta, T.transpose(activations[-l-1])))
  T.set_subtensor(nabla_w[-l], T.dot(delta, T.transpose(inputs[-l-1])))
  func_inputs = list(weights)
  func_inputs.extend(biases)
  func_inputs.append(x)
  func_inputs.append(y)
  
  
  backpropagate = function(func_inputs, [nabla_w, nabla_b])
  </code></pre>