Utility function to view a structured 1D array where all fields have a
    uniform dtype (e.g., an array constructed by :func:calldata) as a 2D array.

    Parameters
    ----------

    a: numpy array or array-like
        The array to be viewed as 2D, must have a uniform dtype

    Returns
    -------

    A 2D view of the array.

    Examples
    --------

    >>> from vcfnp import calldata
    >>> a = calldata('fixture/sample.vcf')
    >>> a
    array([ ((True, True, [0, 0], 0, 0, b'0|0', [10, 10]), (True, True, [0, 0], 0, 0, b'0|0', [10, 10]), (True, False, [0, 1], 0, 0, b'0/1', [3, 3])),
           ((True, True, [0, 0], 0, 0, b'0|0', [10, 10]), (True, True, [0, 0], 0, 0, b'0|0', [10, 10]), (True, False, [0, 1], 0, 0, b'0/1', [3, 3])),
           ((True, True, [0, 0], 1, 48, b'0|0', [51, 51]), (True, True, [1, 0], 8, 48, b'1|0', [51, 51]), (True, False, [1, 1], 5, 43, b'1/1', [0, 0])),
           ((True, True, [0, 0], 3, 49, b'0|0', [58, 50]), (True, True, [0, 1], 5, 3, b'0|1', [65, 3]), (True, False, [0, 0], 3, 41, b'0/0', [0, 0])),
           ((True, True, [1, 2], 6, 21, b'1|2', [23, 27]), (True, True, [2, 1], 0, 2, b'2|1', [18, 2]), (True, False, [2, 2], 4, 35, b'2/2', [0, 0])),
           ((True, True, [0, 0], 0, 54, b'0|0', [56, 60]), (True, True, [0, 0], 4, 48, b'0|0', [51, 51]), (True, False, [0, 0], 2, 61, b'0/0', [0, 0])),
           ((True, False, [0, 1], 4, 0, b'0/1', [0, 0]), (True, False, [0, 2], 2, 17, b'0/2', [0, 0]), (False, False, [-1, -1], 3, 40, b'./.', [0, 0])),
           ((True, False, [0, 0], 0, 0, b'0/0', [0, 0]), (True, True, [0, 0], 0, 0, b'0|0', [0, 0]), (False, False, [-1, -1], 0, 0, b'./.', [0, 0])),
           ((True, False, [0, -1], 0, 0, b'0', [0, 0]), (True, False, [0, 1], 0, 0, b'0/1', [0, 0]), (True, True, [0, 2], 0, 0, b'0|2', [0, 0]))],
          dtype=[('NA00001', [('is_called', '?'), ('is_phased', '?'), ('genotype', 'i1', (2,)), ('DP', '<u2'), ('GQ', 'u1'), ('GT', 'S3'), ('HQ', '<i4', (2,))]), ('NA00002', [('is_called', '?'), ('is_phased', '?'), ('genotype', 'i1', (2,)), ('DP', '<u2'), ('GQ', 'u1'), ('GT', 'S3'), ('HQ', '<i4', (2,))]), ('NA00003', [('is_called', '?'), ('is_phased', '?'), ('genotype', 'i1', (2,)), ('DP', '<u2'), ('GQ', 'u1'), ('GT', 'S3'), ('HQ', '<i4', (2,))])])
    >>> from vcfnp import view2d
    >>> b = view2d(a)
    >>> b
    array([[(True, True, [0, 0], 0, 0, b'0|0', [10, 10]),
            (True, True, [0, 0], 0, 0, b'0|0', [10, 10]),
            (True, False, [0, 1], 0, 0, b'0/1', [3, 3])],
           [(True, True, [0, 0], 0, 0, b'0|0', [10, 10]),
            (True, True, [0, 0], 0, 0, b'0|0', [10, 10]),
            (True, False, [0, 1], 0, 0, b'0/1', [3, 3])],
           [(True, True, [0, 0], 1, 48, b'0|0', [51, 51]),
            (True, True, [1, 0], 8, 48, b'1|0', [51, 51]),
            (True, False, [1, 1], 5, 43, b'1/1', [0, 0])],
           [(True, True, [0, 0], 3, 49, b'0|0', [58, 50]),
            (True, True, [0, 1], 5, 3, b'0|1', [65, 3]),
            (True, False, [0, 0], 3, 41, b'0/0', [0, 0])],
           [(True, True, [1, 2], 6, 21, b'1|2', [23, 27]),
            (True, True, [2, 1], 0, 2, b'2|1', [18, 2]),
            (True, False, [2, 2], 4, 35, b'2/2', [0, 0])],
           [(True, True, [0, 0], 0, 54, b'0|0', [56, 60]),
            (True, True, [0, 0], 4, 48, b'0|0', [51, 51]),
            (True, False, [0, 0], 2, 61, b'0/0', [0, 0])],
           [(True, False, [0, 1], 4, 0, b'0/1', [0, 0]),
            (True, False, [0, 2], 2, 17, b'0/2', [0, 0]),
            (False, False, [-1, -1], 3, 40, b'./.', [0, 0])],
           [(True, False, [0, 0], 0, 0, b'0/0', [0, 0]),
            (True, True, [0, 0], 0, 0, b'0|0', [0, 0]),
            (False, False, [-1, -1], 0, 0, b'./.', [0, 0])],
           [(True, False, [0, -1], 0, 0, b'0', [0, 0]),
            (True, False, [0, 1], 0, 0, b'0/1', [0, 0]),
            (True, True, [0, 2], 0, 0, b'0|2', [0, 0])]],
          dtype=[('is_called', '?'), ('is_phased', '?'), ('genotype', 'i1', (2,)), ('DP', '<u2'), ('GQ', 'u1'), ('GT', 'S3'), ('HQ', '<i4', (2,))])
    >>> b['GT']
    array([[b'0|0', b'0|0', b'0/1'],
           [b'0|0', b'0|0', b'0/1'],
           [b'0|0', b'1|0', b'1/1'],
           [b'0|0', b'0|1', b'0/0'],
           [b'1|2', b'2|1', b'2/2'],
           [b'0|0', b'0|0', b'0/0'],
           [b'0/1', b'0/2', b'./.'],
           [b'0/0', b'0|0', b'./.'],
           [b'0', b'0/1', b'0|2']],
          dtype='|S3')
    >>> b['genotype']
    array([[[ 0,  0],
            [ 0,  0],
            [ 0,  1]],
           [[ 0,  0],
            [ 0,  0],
            [ 0,  1]],
           [[ 0,  0],
            [ 1,  0],
            [ 1,  1]],
           [[ 0,  0],
            [ 0,  1],
            [ 0,  0]],
           [[ 1,  2],
            [ 2,  1],
            [ 2,  2]],
           [[ 0,  0],
            [ 0,  0],
            [ 0,  0]],
           [[ 0,  1],
            [ 0,  2],
            [-1, -1]],
           [[ 0,  0],
            [ 0,  0],
            [-1, -1]],
           [[ 0, -1],
            [ 0,  1],
            [ 0,  2]]], dtype=int8)

def view2d(a):
    """
    Utility function to view a structured 1D array where all fields have a
    uniform dtype (e.g., an array constructed by :func:calldata) as a 2D array.

    Parameters
    ----------

    a: numpy array or array-like
        The array to be viewed as 2D, must have a uniform dtype

    Returns
    -------

    A 2D view of the array.

    Examples
    --------

    >>> from vcfnp import calldata
    >>> a = calldata('fixture/sample.vcf')
    >>> a
    array([ ((True, True, [0, 0], 0, 0, b'0|0', [10, 10]), (True, True, [0, 0], 0, 0, b'0|0', [10, 10]), (True, False, [0, 1], 0, 0, b'0/1', [3, 3])),
           ((True, True, [0, 0], 0, 0, b'0|0', [10, 10]), (True, True, [0, 0], 0, 0, b'0|0', [10, 10]), (True, False, [0, 1], 0, 0, b'0/1', [3, 3])),
           ((True, True, [0, 0], 1, 48, b'0|0', [51, 51]), (True, True, [1, 0], 8, 48, b'1|0', [51, 51]), (True, False, [1, 1], 5, 43, b'1/1', [0, 0])),
           ((True, True, [0, 0], 3, 49, b'0|0', [58, 50]), (True, True, [0, 1], 5, 3, b'0|1', [65, 3]), (True, False, [0, 0], 3, 41, b'0/0', [0, 0])),
           ((True, True, [1, 2], 6, 21, b'1|2', [23, 27]), (True, True, [2, 1], 0, 2, b'2|1', [18, 2]), (True, False, [2, 2], 4, 35, b'2/2', [0, 0])),
           ((True, True, [0, 0], 0, 54, b'0|0', [56, 60]), (True, True, [0, 0], 4, 48, b'0|0', [51, 51]), (True, False, [0, 0], 2, 61, b'0/0', [0, 0])),
           ((True, False, [0, 1], 4, 0, b'0/1', [0, 0]), (True, False, [0, 2], 2, 17, b'0/2', [0, 0]), (False, False, [-1, -1], 3, 40, b'./.', [0, 0])),
           ((True, False, [0, 0], 0, 0, b'0/0', [0, 0]), (True, True, [0, 0], 0, 0, b'0|0', [0, 0]), (False, False, [-1, -1], 0, 0, b'./.', [0, 0])),
           ((True, False, [0, -1], 0, 0, b'0', [0, 0]), (True, False, [0, 1], 0, 0, b'0/1', [0, 0]), (True, True, [0, 2], 0, 0, b'0|2', [0, 0]))],
          dtype=[('NA00001', [('is_called', '?'), ('is_phased', '?'), ('genotype', 'i1', (2,)), ('DP', '<u2'), ('GQ', 'u1'), ('GT', 'S3'), ('HQ', '<i4', (2,))]), ('NA00002', [('is_called', '?'), ('is_phased', '?'), ('genotype', 'i1', (2,)), ('DP', '<u2'), ('GQ', 'u1'), ('GT', 'S3'), ('HQ', '<i4', (2,))]), ('NA00003', [('is_called', '?'), ('is_phased', '?'), ('genotype', 'i1', (2,)), ('DP', '<u2'), ('GQ', 'u1'), ('GT', 'S3'), ('HQ', '<i4', (2,))])])
    >>> from vcfnp import view2d
    >>> b = view2d(a)
    >>> b
    array([[(True, True, [0, 0], 0, 0, b'0|0', [10, 10]),
            (True, True, [0, 0], 0, 0, b'0|0', [10, 10]),
            (True, False, [0, 1], 0, 0, b'0/1', [3, 3])],
           [(True, True, [0, 0], 0, 0, b'0|0', [10, 10]),
            (True, True, [0, 0], 0, 0, b'0|0', [10, 10]),
            (True, False, [0, 1], 0, 0, b'0/1', [3, 3])],
           [(True, True, [0, 0], 1, 48, b'0|0', [51, 51]),
            (True, True, [1, 0], 8, 48, b'1|0', [51, 51]),
            (True, False, [1, 1], 5, 43, b'1/1', [0, 0])],
           [(True, True, [0, 0], 3, 49, b'0|0', [58, 50]),
            (True, True, [0, 1], 5, 3, b'0|1', [65, 3]),
            (True, False, [0, 0], 3, 41, b'0/0', [0, 0])],
           [(True, True, [1, 2], 6, 21, b'1|2', [23, 27]),
            (True, True, [2, 1], 0, 2, b'2|1', [18, 2]),
            (True, False, [2, 2], 4, 35, b'2/2', [0, 0])],
           [(True, True, [0, 0], 0, 54, b'0|0', [56, 60]),
            (True, True, [0, 0], 4, 48, b'0|0', [51, 51]),
            (True, False, [0, 0], 2, 61, b'0/0', [0, 0])],
           [(True, False, [0, 1], 4, 0, b'0/1', [0, 0]),
            (True, False, [0, 2], 2, 17, b'0/2', [0, 0]),
            (False, False, [-1, -1], 3, 40, b'./.', [0, 0])],
           [(True, False, [0, 0], 0, 0, b'0/0', [0, 0]),
            (True, True, [0, 0], 0, 0, b'0|0', [0, 0]),
            (False, False, [-1, -1], 0, 0, b'./.', [0, 0])],
           [(True, False, [0, -1], 0, 0, b'0', [0, 0]),
            (True, False, [0, 1], 0, 0, b'0/1', [0, 0]),
            (True, True, [0, 2], 0, 0, b'0|2', [0, 0])]],
          dtype=[('is_called', '?'), ('is_phased', '?'), ('genotype', 'i1', (2,)), ('DP', '<u2'), ('GQ', 'u1'), ('GT', 'S3'), ('HQ', '<i4', (2,))])
    >>> b['GT']
    array([[b'0|0', b'0|0', b'0/1'],
           [b'0|0', b'0|0', b'0/1'],
           [b'0|0', b'1|0', b'1/1'],
           [b'0|0', b'0|1', b'0/0'],
           [b'1|2', b'2|1', b'2/2'],
           [b'0|0', b'0|0', b'0/0'],
           [b'0/1', b'0/2', b'./.'],
           [b'0/0', b'0|0', b'./.'],
           [b'0', b'0/1', b'0|2']],
          dtype='|S3')
    >>> b['genotype']
    array([[[ 0,  0],
            [ 0,  0],
            [ 0,  1]],
           [[ 0,  0],
            [ 0,  0],
            [ 0,  1]],
           [[ 0,  0],
            [ 1,  0],
            [ 1,  1]],
           [[ 0,  0],
            [ 0,  1],
            [ 0,  0]],
           [[ 1,  2],
            [ 2,  1],
            [ 2,  2]],
           [[ 0,  0],
            [ 0,  0],
            [ 0,  0]],
           [[ 0,  1],
            [ 0,  2],
            [-1, -1]],
           [[ 0,  0],
            [ 0,  0],
            [-1, -1]],
           [[ 0, -1],
            [ 0,  1],
            [ 0,  2]]], dtype=int8)

    """  # flake8: noqa

    rows = a.size
    cols = len(a.dtype)
    dtype = a.dtype[0]
    b = a.view(dtype).reshape(rows, cols)
    return b