title: Design pattern for transposing array slices/shapes
body: <p>I'm working on a object oriented image processing module. Depending on whether my regions are vertical or horizontal I have to slice and pad them differently. I came up with Vertical and Horizontal classes that implement <code>set_slice_to_value</code> and <code>get_shape</code> methods to avoid if/elses:</p>
  <pre><code>class Vertical:
  
    template_zeros = &quot;y&quot;
    mask_pad = &quot;x&quot;
    axis = 0
    dim = 1
  
    def set_slice_to_value(array, start, end, value, axis):
      if axis == &quot;y&quot;:
        array[start:end,:] = value
      else:
        array[:,start:end] = value
      return array
  
    def get_shape(dims):
      return (max(dims), min(dims))
  </code></pre>
  <pre><code>self._orientation = &quot;vertical&quot; if image.shape[0] &gt; image.shape[1] else &quot;horizontal&quot; # old
  self._orientation = Vertical() if image.shape[0] &gt; image.shape[1] else Horizontal() # new
  </code></pre>
  <pre><code>if self._orientation == &quot;vertical&quot;:
        mask[:,pad:-pad] = rolled
  else: 
        mask[pad:-pad,:] = rolled # old 
  
  mask = self._orientation.set_slice_to_value(mask, pad, -pad, rolled, self._orientation.mask_pad) # new
  </code></pre>
  <pre><code>template_shape = [self._long_edge, self._frame_short]
  template = np.ones(tuple(template_shape)) if self._orientation == &quot;vertical&quot; 
                                            else np.ones(tuple(template_shape.reverse())) # old
  
  template = np.ones(self._orientation.get_shape([self._long_edge, self._frame_short])) # new
  </code></pre>
  <p>This still sounds a bit verbose though. Is there a cleaner way to do this?</p>