title: python shift 3-d array
body: <p>I have a 3-dimensional array in python.  I want to shift the [z][y][x] "cube" on the first [z] index.  But the number of shifts will vary depending on [y] and [x].  In other words, I wish I could feed numpy.roll something like numpy.roll(3Darray, 2Dvector, axis=0), where 2Dvector would specify the amount of the shift for each [y][x].  Sorry if this is a poor description, I'm new to this.</p>
  
  <p>Here's an example using a non-sense 3-D array.  The first 2-D slice is all integers, the second slice is upper case letters, the third is lower case letters.  I chose this just so it's more obvious what's "moving".</p>
  
  <pre><code>old_array([[[6 3 9]
              [4 4 8]
              [3 1 6]]
  
             [[A C F]
              [T Z Q]
              [L M P]]
  
             [[b z j]
              [q o k]
              [u y r]]])
  </code></pre>
  
  <p>Now I want to roll the first slice around to the 3rd slice IF the value in the first slice is less than 5.  The result would look like this:</p>
  
  <pre><code>new_array([[[6 C 9]
              [T Z 8]
              [L M 6]]
  
              [[A z F]
               [q o Q]
               [u y P]]
  
              [[b 3 j]
               [4 4 k]
               [3 1 r]]])
  </code></pre>
  
  <p>I've tried something like:</p>
  
  <pre><code> a[a[0]&lt;5] = np.roll(a[a[0]&lt;5],1,axis=0)
  </code></pre>
  
  <p>but didn't get the result I wanted no matter what I chose for my axis setting.</p>