title: Indexing for 3 dimensional Numpy Arrays (convolutional network)
body: <p>I'm trying to write a function that performs Convolution, and I'm getting a little challenged trying to create the output volume using numpy. Specifically, I have an input image that is represented as an array of dimensions (150,150,3). Now, I want to convolve over this image with a set of kernels num_kernels, which are arrays of dimension (4,4,3), and I want these kernels to move over the image with a stride of 2. My thought process has been: </p>
  
  <p>(1) I'll create an output array which is comprised of taking (4,4,3) size chunks out of the input array and stretching these out into rows, and ultimately making a large matrix of these. </p>
  
  <p>(2) Then, I'll create a parameter array composed of all of my (4,4,3) kernels stretched out into rows, which will also make a large matrix. </p>
  
  <p>(3) Then I can dot product these matrices together and reshape the output matrix into the proper dimensions. </p>
  
  <p>My rough psuedo-code start to number (1) is as follows. </p>
  
  <pre><code>def Convolution(input, filter_size, num_filters, stride):
      X = input 
      output_Volume = np.zeros(#dimensions)
      weights = np.zeros(#dimensions)
      #get weights from other function
      for width in range(0,150,2):
          for height in range(0,150,2):
              row = X(#indexes here to take out chunk).flatten
              output_Volume.append(row) #something of this sort
      return #dot product output volume and weights   
  </code></pre>
  
  <p>If someone could provide a specific code example of how to implement this (most helpful would be answers to (1) and (2)) in Python (I'm using numpy), it would be much appreciated. Thank you!</p>