शुरू करेंमुफ़्त में शुरू करें

डीप डाइव - Twitter नेटवर्क

अब आप Twitter नेटवर्क में एक डीप डाइव करने जा रहे हैं, जो आपने पहले सीखा है उसे और पक्का करेगा. सबसे पहले, आप उन नोड्स को ढूँढेंगे जो एक डिग्री दूर बहुत से लोगों तक संदेश बहुत कुशलता से प्रसारित कर सकते हैं.

NetworkX आपके लिए पहले से nx नाम से इम्पोर्ट किया गया है.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में नेटवर्क विश्लेषण का परिचय

पाठ्यक्रम देखें

अभ्यास निर्देश

  • एक फंक्शन find_nodes_with_highest_deg_cent(G) लिखें जो निम्न चरणों का उपयोग करके सर्वाधिक degree centrality वाले नोड/नोड्स लौटाए:
    • G की degree centrality compute करें.
    • list(deg_cent.values()) पर max() फंक्शन लगाकर अधिकतम degree centrality निकालें.
    • degree centrality की dictionary deg_cent.items() पर iterate करें.
    • यदि मौजूदा नोड k का degree centrality मान v max_dc के बराबर है, तो उसे nodes के सेट में जोड़ दें.
  • अपने फंक्शन का उपयोग करके T में सर्वाधिक degree centrality वाला/वाले नोड ढूँढें.
  • एक assertion स्टेटमेंट लिखें जो जाँच करे कि नोड/नोड्स सही तरह से पहचाने गए हैं. यह आपके लिए कर दिया गया है, तो परिणाम देखने के लिए 'Submit Answer' दबाएँ!

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Define find_nodes_with_highest_deg_cent()
def find_nodes_with_highest_deg_cent(G):

    # Compute the degree centrality of G: deg_cent
    deg_cent = ____

    # Compute the maximum degree centrality: max_dc
    max_dc = ____

    nodes = set()

    # Iterate over the degree centrality dictionary
    for k, v in ____:

        # Check if the current value has the maximum degree centrality
        if ____ == ____:

            # Add the current node to the set of nodes
            ____

    return nodes

# Find the node(s) that has the highest degree centrality in T: top_dc
top_dc = ____
print(top_dc)

# Write the assertion statement
for node in top_dc:
    assert nx.degree_centrality(T)[node] == max(nx.degree_centrality(T).values())
कोड संपादित करें और चलाएँ