networkx

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

NetworkX Graph Analysis

NetworkX 图分析

Python library for creating, analyzing, and visualizing networks and graphs.
一款用于创建、分析和可视化网络与图的Python库。

When to Use

适用场景

  • Social network analysis
  • Knowledge graphs and ontologies
  • Shortest path problems
  • Community detection
  • Citation/reference networks
  • Biological networks (protein interactions)

  • 社交网络分析
  • 知识图谱与本体
  • 最短路径问题
  • 社区检测
  • 引用/参考文献网络
  • 生物网络(蛋白质相互作用)

Graph Types

图类型

TypeEdgesMultiple Edges
Graph
UndirectedNo
DiGraph
DirectedNo
MultiGraph
UndirectedYes
MultiDiGraph
DirectedYes

类型边类型允许多条边
Graph
无向
DiGraph
有向
MultiGraph
无向
MultiDiGraph
有向

Key Algorithms

核心算法

Centrality Measures

中心性指标

MeasureWhat It FindsUse Case
DegreeMost connectionsPopular nodes
BetweennessBridge nodesInformation flow
ClosenessFastest reachEfficient spreaders
PageRankImportanceWeb pages, citations
EigenvectorInfluential connectionsWho knows important people
指标作用适用场景
Degree找出连接数最多的节点热门节点识别
Betweenness找出桥接节点信息流分析
Closeness找出最易触达的节点高效传播者识别
PageRank评估节点重要性网页排名、引用分析
Eigenvector找出连接重要节点的节点影响力节点识别

Path Algorithms

路径算法

AlgorithmPurpose
Shortest pathMinimum hops
Weighted shortestMinimum cost
All pairs shortestFull distance matrix
DijkstraEfficient weighted paths
算法用途
Shortest path寻找最少跳数路径
Weighted shortest寻找最低成本路径
All pairs shortest生成全节点距离矩阵
Dijkstra高效寻找带权路径

Community Detection

社区检测

MethodApproach
LouvainModularity optimization
Greedy modularityHierarchical merging
Label propagationFast, scalable

方法实现思路
Louvain模块度优化
Greedy modularity层次化合并
Label propagation快速、可扩展

Graph Generators

图生成器

GeneratorModel
Erdős-RényiRandom edges
Barabási-AlbertPreferential attachment (scale-free)
Watts-StrogatzSmall-world
CompleteAll connected

生成器模型
Erdős-Rényi随机边模型
Barabási-Albert偏好依附模型(无标度)
Watts-Strogatz小世界模型
Complete全连接模型

Layout Algorithms

布局算法

LayoutBest For
SpringGeneral purpose
CircularRegular structure
Kamada-KawaiAesthetics
SpectralClustered graphs

布局最佳适用场景
Spring通用场景
Circular规则结构
Kamada-Kawai美观性优先
Spectral聚类图

I/O Formats

输入输出格式

FormatPreserves AttributesHuman Readable
GraphMLYesYes (XML)
Edge listNoYes
JSONYesYes
PandasYesVia DataFrame

格式保留属性人类可读性
GraphML是(XML格式)
Edge list
JSON
Pandas通过DataFrame实现

Performance Considerations

性能考量

ScaleApproach
< 10K nodesAny algorithm
10K - 100KUse approximate algorithms
> 100KConsider graph-tool or igraph
Key concept: NetworkX is pure Python - great for prototyping, may need alternatives for production scale.

规模处理方案
< 10K 节点任意算法均可
10K - 100K 节点使用近似算法
> 100K 节点考虑使用graph-tool或igraph
核心概念:NetworkX是纯Python实现的库,非常适合原型开发,但生产环境大规模场景可能需要替代方案。

Best Practices

最佳实践

  • Set random seeds for reproducibility
  • Choose correct graph type upfront
  • Use pandas integration for data exchange
  • Consider memory for large graphs
  • 设置随机种子以保证结果可复现
  • 提前选择正确的图类型
  • 使用pandas集成进行数据交换
  • 处理大图时注意内存限制

Resources

参考资源