title: Numpy 2d and 1d array to latex bmatrix
body: <p>I'm looking for a clean way to migrate numpy arrays to latex bmatrix. It should work for both 2d arrays and horizontal and vertical 1d array.</p>
  
  <p><strong>Example</strong></p>
  
  <pre><code>A = array([[12, 5, 2],
             [20, 4, 8],
             [ 2, 4, 3],
             [ 7, 1,10]])
  
  print A              #2d array
  print A[0]           #horizontal array
  print A[:,0, None]   #vertical array
  
  array_to_bmatrix(A)
  array_to_bmatrix(A[0])
  array_to_bmatrix(A[:,0, None])
  </code></pre>
  
  <p>Out:</p>
  
  <pre><code>[[12  5  2]
   [20  4  8]
   [ 2  4  3]
   [ 7  1 10]]
  
  [12  5  2]
  
  [[12]
   [20]
   [ 2]
   [ 7]]
  
  \begin{bmatrix} 
   12.000 &amp; 5.000 &amp; 2.000 &amp; \\
   20.000 &amp; 4.000 &amp; 8.000 &amp; \\
   2.000 &amp; 4.000 &amp; 3.000 &amp; \\
   7.000 &amp; 1.000 &amp; 10.000 &amp; \\
  \end{bmatrix}
  
  \begin{bmatrix} 
   12.000 &amp; 5.000 &amp; 2.000
  \end{bmatrix}
  
  \begin{bmatrix} 
   12.000 &amp; \\
   20.000 &amp; \\
   2.000 &amp; \\
   7.000 &amp; \\
  \end{bmatrix}
  </code></pre>
  
  <p><strong>Attempt of solution</strong></p>
  
  <pre><code>def array_to_bmatrix(array):
      begin = '\\begin{bmatrix} \n'
      data = ''
      for line in array:        
          if line.size == 1:
              data = data + ' %.3f &amp;'%line
              data = data + r' \\'
              data = data + '\n'
              continue
          for element in line:
              data = data + ' %.3f &amp;'%element
  
          data = data + r' \\'
          data = data + '\n'
      end = '\end{bmatrix}'
      print begin + data + end  
  </code></pre>
  
  <p>This solution works for vertical and 2d arrays, however it outputs horizontal arrays as vertical ones.</p>
  
  <pre><code>array_to_bmatrix(A[0])
  </code></pre>
  
  <p>Out:</p>
  
  <pre><code>\begin{bmatrix} 
   12.000 &amp; \\
   5.000 &amp; \\
   2.000 &amp; \\
  \end{bmatrix}
  </code></pre>