def assign_node_centroids(G, centroids):
    """
    Modify the nodal attributes "centroids", "x", "y", and "z" of nodes
    of G, inplace. "centroids" will be set according to the scheme
    ``G[i]["centroids"] = centroids[i]``
    for nodes ``i`` in ``G``. "x", "y" and "z" are assigned as the first,
    second and third coordinate of ``centroids[i]`` respectively.

    Parameters
    ----------
    G : :class:`networkx.Graph`
    centroids : list
        ``centroids[i]`` is a tuple representing the cartesian coordinates of
        node ``i`` in ``G``

    Returns
    -------
    :class:`networkx.Graph`
        graph with nodal attributes modified
    """
    # Assign cartesian coordinates to the nodes
    for i, node in enumerate(G.nodes()):
        G.node[i]['x'] = centroids[i][0]
        G.node[i]['y'] = centroids[i][1]
        G.node[i]['z'] = centroids[i][2]
        G.node[i]['centroids'] = centroids[i]
    #
    G.graph['centroids'] = True
    return G