title: Formatting a 2D Numpy Array Float -> Percentage
body: <p>I have a 2D numpy array like</p>
  
  <p><code>x = np.array([[3,3],[3,1]])</code></p>
  
  <pre><code>Out[107]: 
  array([[3, 3],
         [3, 1]])
  </code></pre>
  
  <p>I would like to format it to print percentages of the total:</p>
  
  <pre><code>array([['33.3%', '33.3%'],
         ['33.3%', '10.0%']]
  </code></pre>
  
  <p>I've tried some solutions from <a href="https://stackoverflow.com/questions/21008858/formatting-floats-in-a-numpy-array">here</a> and <a href="https://stackoverflow.com/questions/2891790/how-to-pretty-printing-a-numpy-array-without-scientific-notation-and-with-given">here</a> but have yet to get these to work:</p>
  
  <pre><code>pct_formatter = lambda x: "{:.2%}".format(x/x.sum() * 100 )
  pct_formatter(x)
  
  TypeError: non-empty format string passed to object.__format__
  </code></pre>
  
  <p>another attempt:</p>
  
  <pre><code>with np.set_printoptions(formatter=pct_formatter):
      print(pct_formatter(x))
  
  AttributeError: __exit__
  </code></pre>