시작하기무료로 시작하기

시간에 따른 그래프 차이

이제 시간에 따른 그래프 차이를 계산해 보겠습니다! 가장 단순한 경우를 살펴보기 위해, 여기서는 (month, month + 1) 구간을 사용하고 시간이 지나면서 추가되거나 사라진 엣지를 추적할 거예요. 이 연습 문제는 다음 연습 문제에서 시간에 따른 변화를 시각화하기 위한 준비 단계입니다.

이 연습은 강의의 일부입니다

Python 중급 네트워크 분석

강의 보기

연습 안내

  • for 루프 안에서:
    • Gs[i]g1에, Gs[i + window]g2에 할당하세요.
    • nx.difference()를 사용해 g2g1의 차이를 계산하고 결과를 added에 추가하세요.
    • g1g2의 차이를 removed에 추가하세요.
  • fractional_changes를 출력하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

import networkx as nx  
# Instantiate a list of graphs that show edges added: added
added = []
# Instantiate a list of graphs that show edges removed: removed
removed = []
# Here's the fractional change over time
fractional_changes = []
window = 1

for i in range(len(Gs) - window):
    g1 = Gs[____]
    g2 = Gs[____ + ____]
        
    # Compute graph difference here
    added.append(____)   
    removed.append(____)
    
    # Compute change in graph size over time
    fractional_changes.append((len(g2.edges()) - len(g1.edges())) / len(g1.edges()))
    
# Print the fractional change
print(____)
코드 편집 및 실행