title: Accessing Data of a Theano Shared Variable
body: <p>I'v successfully loaded the MNIST dataset into Theano shared variables as follows</p>
  
  <pre><code># Read MNIST dataset from gzipped file as binary
  f = gzip.open('mnist.pkl.gz', 'rb')
  # Store dataset into variable
  train_set = cPickle.load(f)
  # Close zipped file
  f.close()
  # Store data in Theano shared variable
  train_set_x = theano.shared(numpy.asarray(train_set, dtype=theano.config.floatX)) # Data
  train_set_y = theano.shared(numpy.asarray(train_set, dtype=theano.config.floatX)) # Labels
  # Cast labels into int
  train_set_y = theano.tensor.cast(train_set_y, 'int32')
  </code></pre>
  
  <p>My question is how do I access the data in both train_set_x and train_set_y. Each image in the data set is 28 * 28 pixels. That is a vector of length 784 with all elements in the vector as floats representing values between 0.0 and 1.0 inclusive. The labels are casted into int because it represents the label associated to each vector image and is a value between 0 and 9. I want to be able to loop over the train_set_x matrix images and train_set_y labels to view the data of each image and its label separately and eventually plot the images on screen.</p>