def number_of_nodes(shape, node_layout='rect'):
    """Get the number of nodes in a hex graph.

    Parameters
    ----------
    shape : tuple of int
        Number of rows and columns of the hex grid. The first value
        is the number of nodes in the first column and the second the
        number of nodes in the first column.

    Examples
    --------
    >>> from landlab.graph.hex.hex import number_of_nodes
    >>> number_of_nodes((3, 2))
    6
    >>> number_of_nodes((2, 4))
    8
    >>> number_of_nodes((4, 2))
    8

    >>> number_of_nodes((3, 2), node_layout='hex')
    7
    >>> number_of_nodes((2, 4), node_layout='hex')
    9
    >>> number_of_nodes((4, 2), node_layout='hex')
    12

    >>> number_of_nodes((3, 2), node_layout='rect1')
    7
    >>> number_of_nodes((2, 4), node_layout='rect1')
    9
    >>> number_of_nodes((4, 2), node_layout='rect1')
    10
    """
    if node_layout not in ('rect', 'hex', 'rect1'):
        raise ValueError('node_layout not understood')

    n_rows, n_cols = shape

    if node_layout == 'rect':
        return n_rows * n_cols
    elif node_layout == 'hex':
        return  n_rows * n_cols + (n_rows // 2) ** 2
    elif node_layout == 'rect1':
        return (2 * n_cols + 1) * (n_rows // 2) + n_cols * (n_rows % 2)