
    wgn                     J    d Z ddlZdgZ ej                  d      dd       Zy)z
Spectral bipartivity measure.
    Nspectral_bipartivityweight)
edge_attrsc           
         ddl }t        |       }t        j                  | ||      }|j                  j                  |      }|j                  j                  |       }d||z   z  }|Ft        |j                         j                         |j                         j                         z        S t        t        |t        t        |                        }	i }
|D ]/  }|	|   }|j                  ||      |j                  ||      z  |
|<   1 |
S )u9  Returns the spectral bipartivity.

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

    nodes : list or container  optional(default is all nodes)
      Nodes to return value of spectral bipartivity contribution.

    weight : string or None  optional (default = 'weight')
      Edge data key to use for edge weights. If None, weights set to 1.

    Returns
    -------
    sb : float or dict
       A single number if the keyword nodes is not specified, or
       a dictionary keyed by node with the spectral bipartivity contribution
       of that node as the value.

    Examples
    --------
    >>> from networkx.algorithms import bipartite
    >>> G = nx.path_graph(4)
    >>> bipartite.spectral_bipartivity(G)
    1.0

    Notes
    -----
    This implementation uses Numpy (dense) matrices which are not efficient
    for storing large sparse graphs.

    See Also
    --------
    color

    References
    ----------
    .. [1] E. Estrada and J. A. Rodríguez-Velázquez, "Spectral measures of
       bipartivity in complex networks", PhysRev E 72, 046105 (2005)
    r   N)r   g      ?)scipylistnxto_numpy_arraylinalgexpmfloatdiagonalsumdictziprangelenitem)Gnodesr   spnodelistAexpAexpmAcoshAindexsbnis                k/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/networkx/algorithms/bipartite/spectral.pyr   r   
   s    T AwH
!Xf5A99>>!DIINNA2E4%< E}U^^%))+dmmo.A.A.CCDD S5X#789 	7AaAJJq!$tyyA6BqE	7 	    )Nr   )__doc__networkxr	   __all___dispatchabler    r"   r!   <module>r(      s8    !
" X&: ':r"   