def assortativity_attributes(user):

    matrix = matrix_undirected_unweighted(user)

    neighbors = [k for k in user.network.keys() if k != user.name]
    neighbors_attrbs = {}
    for i, u_name in enumerate(matrix_index(user)):
        correspondent = user.network.get(u_name, None)
        if correspondent is None or u_name == user.name or matrix[0][i] == 0:
            continue

        if correspondent.has_attributes:
            neighbors_attrbs[correspondent.name] = correspondent.attributes

    assortativity = {}
    for a in user.attributes:
        total = sum(1 for n in neighbors if n in neighbors_attrbs and user.attributes[a] == neighbors_attrbs[n][a])
        den = sum(1 for n in neighbors if n in neighbors_attrbs)
        assortativity[a] = total / den if den != 0 else None

    return assortativity
Computes the assortativity of the nominal attributes.
dataset/ETHPy150Open yvesalexandre/bandicoot/bandicoot/network.py/assortativity_attributes