||
这学期即上《python》,又上《线性代数》课,都是“好课”,可按排的学时都不多。
用python语言编写了一个示例,调用networkx和matplotlib绘制结点关系图。
简单整理一下《线性代数》课程中的概念,看图可引导学生复习,回顾概念之间的关系。
(结点间联系其实很多,只画主要部分)
完整代码如下:
import networkx as nx
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
L=["矩阵","方阵","逆矩阵","伴随矩阵","行列式","特征值","特征向量","二次型","秩",
"维","向量","范数","向量组","解集","增广矩阵","行最简形","基","余子阵",
"线性方程组","线性组合","线性表示","线性相关","线性关系","线性空间",
"线性算子","行空间","列空间","零空间","正交","转置","内积","初等变换",
"线性运算","线性映射","线性变换","对换","数乘","倍加"]
E=[(12,0),(10,12),(0, 1),(1,4),(1,5),(1,6),(5,6),(12, 23),(10,23),(30,10)
,(10,28),(11,10),(1,2),(1,3),(1,7),(1,17),(18,14),(15,14),(15,31)
,(15,8),(14,31),(31,35),(31,36),(31,37),(18,20),(20,21),(12,21),(19,12)
,(13,8),(18,13),(23,34),(23,12),(0,8),(33,34),(34,22),(34,32),(0,24)
,(0,25),(0,26),(18,34),(0,27),(13,27),(23,16),(23,9),(0,29)]
G = nx.Graph()
G.add_nodes_from(L)
G.add_edges_from([(L[i[0]],L[i[1]]) for i in E])
nx.draw(G,with_labels=True, node_size=600,edge_color='black', font_size=18,
node_color=['skyblue' if i<28 else 'lightcyan' for i in range(len(L))])
plt.show()
#draw_circular
python实现了很多常用数据结构,尤其是列表推导式、字典等,处理数据很方便。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-25 02:33
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社