Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. def bmatrix(a):
  2. """Returns a LaTeX bmatrix
  3.  
  4. :a: numpy array
  5. :returns: LaTeX bmatrix as a string
  6. """
  7. if len(a.shape) > 2:
  8. raise ValueError('bmatrix can at most display two dimensions')
  9. lines = str(a).replace('[', '').replace(']', '').splitlines()
  10. rv = [r'\begin{bmatrix}']
  11. rv += [' ' + ' & '.join(l.split()) + r'\\' for l in lines]
  12. rv += [r'\end{bmatrix}']
  13. return '\n'.join(rv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement