title: Matrix flip horizontal or vertical
body: <p>I am trying to write a python function to flip a matrix horizontal or vertical.  To write a Python function <code>matrixflip(m,d)</code> that takes a two-dimensional matrix and a direction, where d is either 'h' or 'v'. If <code>d == 'h'</code>, the function should return the matrix flipped horizontally. If <code>d == 'v'</code>, the function should return the matrix flipped vertically. For any other values of d, the function should return m unchanged. In all cases, the argument m should remain undisturbed by the function.</p>
  
  <pre><code>import numpy as np
  def matrixflip(m,d):
      m = myl
      myl = np.array([[1, 2], [3, 4]])
      if d=='v': 
          return np.flip(contour, axis=0)
      elif d=='h':
          return np.flip(contour, axis=1)
  </code></pre>
  
  <p>I expect the output as</p>
  
  <pre><code>&gt;&gt;&gt; myl = [[1,2],[3,4]]
  
  &gt;&gt;&gt; myl
  [[1, 2], [3, 4]]  
  
  &gt;&gt;&gt; matrixflip(myl,'h')
  [[2, 1], [4, 3]]
  
  &gt;&gt;&gt; myl
  [[1, 2], [3, 4]]  
  
  &gt;&gt;&gt; matrixflip(myl,'v')
  [[3, 4], [1, 2]]  
  
  &gt;&gt;&gt; myl
  [[1, 2], [3, 4]]  
  </code></pre>