def bmatrix(arr):
    """
    Converts a numpy array (matrix) to a LaTeX bmatrix

    Args:
        arr: Array
    Returns:
        LaTeX bmatrix as a string
    Raises:
        ValueError: If the array has more than two dimensions
    """

    if len(arr.shape) > 2:
        raise ValueError('bmatrix can at most display two dimensions')

    lines = str(arr).replace('[', '').replace(']', '').splitlines()
    latex_str = [r'\begin{bmatrix}']
    latex_str += ['  ' + ' & '.join(line.split()) + r'\\' for line in lines]
    latex_str += [r'\end{bmatrix}']

    return '\n'.join(latex_str)