def google_matrix(G, alpha=0.85, personalization=None,
                  nodelist=None, weight='weight'):
    """Return the Google matrix of the graph.

    Parameters
    -----------
    G : graph
      A NetworkX graph

    alpha : float
      The damping factor

    personalization: dict, optional
       The "personalization vector" consisting of a dictionary with a
       key for every graph node and nonzero personalization value for each node.

    nodelist : list, optional
      The rows and columns are ordered according to the nodes in nodelist.
      If nodelist is None, then the ordering is produced by G.nodes().

    weight : key, optional
      Edge data key to use as weight.  If None weights are set to 1.

    Returns
    -------
    A : NumPy matrix
       Google matrix of the graph

    See Also
    --------
    pagerank, pagerank_numpy, pagerank_scipy
    """
    try:
        import numpy as np
    except ImportError:
        raise ImportError(\
            "google_matrix() requires NumPy: http://scipy.org/")
    # choose ordering in matrix
    if personalization is None: # use G.nodes() ordering
        nodelist=G.nodes()
    else:  # use personalization "vector" ordering
        nodelist=personalization.keys()
        if set(nodelist)!=set(G):
            raise NetworkXError('Personalization vector dictionary'
                                'must have a value for every node')
    M=nx.to_numpy_matrix(G,nodelist=nodelist,weight=weight)
    (n,m)=M.shape # should be square
    if n == 0:
        return M
    # add constant to dangling nodes' row
    dangling=np.where(M.sum(axis=1)==0)
    for d in dangling[0]:
        M[d]=1.0/n
    # normalize
    M=M/M.sum(axis=1)
    # add "teleportation"/personalization
    e=np.ones((n))
    if personalization is not None:
        v=np.array(list(personalization.values()),dtype=float)
    else:
        v=e
    v=v/v.sum()
    P=alpha*M+(1-alpha)*np.outer(e,v)
    return P
dataset/ETHPy150Open gkno/gkno_launcher/src/networkx/algorithms/link_analysis/pagerank_alg.py/google_matrix/original