资源简介
当我们处理完几百几千乃至上万的图论数据后总是不可避免地要对数据进行数据可视化等的分析
,甚至要在画好图的基础上进行一些上层修改,增加连线,高亮特殊点和路径。比如说在Dijks-
tra和 Floyd算法的时候,为了体现出它们的区别(Dijkstra是以起始点为中心向外扩散层层
遍历得到迷宫式推 进最短路径,而 Floyd是考虑i,j之间分为的过点和不过点分类求最小的
区别);或者生成最小二叉树的kruscal和prim算法,分别得出最小网络问题。都需要我们对网
络节点进行归类和数据可视化。
代码片段和文件信息
import networkx as nx
import matplotlib.pyplot as plt
import xlrd
import numpy as np
class Graph_Matrix:
“““
Adjacency Matrix
“““
def __init__(self vertices=[] matrix=[]):
“““
:param vertices:a dict with vertex id and index of matrix such as {vertex:index}
:param matrix: a matrix
“““
self.matrix = matrix
self.edges_dict = {} # {(tail head):weight}
self.edges_array = [] # (tail head weight)
self.vertices = vertices
self.num_edges = 0
# if provide adjacency matrix then create the edges list
if len(matrix) > 0:
if len(vertices) != len(matrix):
raise IndexError
self.edges = self.getAllEdges()
self.num_edges = len(self.edges)
# if do not provide a adjacency matrix but provide the vertices list build a matrix with 0
elif len(vertices) > 0:
self.matrix = [[0 for col in range(len(vertices))] for row in range(len(vertices))]
self.num_vertices = len(self.matrix)
def isOutRange(self x):
try:
if x >= self.num_vertices or x <= 0:
raise IndexError
except IndexError:
print(“节点下标出界“)
def isEmpty(self):
if self.num_vertices == 0:
self.num_vertices = len(self.matrix)
return self.num_vertices == 0
def add_vertex(self key):
if key not in self.vertices:
self.vertices[key] = len(self.vertices) + 1
# add a vertex mean add a row and a column
# add a column for every row
for i in range(self.getVerticesNumbers()):
self.matrix[i].append(0)
self.num_vertices += 1
nRow = [0] * self.num_vertices
self.matrix.append(nRow)
def getVertex(self key):
pass
def add_edges_from_list(self edges_list): # edges_list : [(tail head weight)()]
for i in range(len(edges_list)):
self.add_edge(edges_list[i][0] edges_list[i][1] edges_list[i][2] )
def add_edge(self tail head cost=0):
# if self.vertices.index(tail) >= 0:
# self.addVertex(tail)
if tail not in self.vertices:
self.add_vertex(tail)
# if self.vertices.index(head) >= 0:
# self.addVertex(head)
if head not in self.vertices:
self.add_vertex(head)
# for directory matrix
self.matrix[self.vertices.index(tail)][self.vertices.index(head)] = cost
# for non-directory matrix
# self.matrix[self.vertices.index(fromV)][self.vertices.index(toV)] = \
# self.matrix[self.vertices.index(toV)][self.vertices.index(fromV)] = cost
self.edges_dict[(tail head)] = cost
self.edges_array.append((tail head cost))
self.num_edges = len(self.edges_dict)
def getEdges(self V):
pass
d
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 113664 2020-08-17 17:23 data1.xls
文件 8793 2020-08-17 15:54 pic.py
相关资源
- echarts大数据可视化新能源车联网综合
- pip-10.0.1.tar.gz
- Data Science from Scratch 2nd Edition
- shape_predictor_68_face_landmarks.dat.bz2 68个标
- 爬取豆瓣电影TOP250程序,包含非常详
- 中文维基百科语料库百度网盘网址.
- MSCNN_dehaze.rar
- 爬取豆瓣排行榜电影数据(含GUI界面
- 字典文本资源
- Brainfuck / OoK 解码脚本
- 案例实战信用卡欺诈检测数据集
- 招商策略_抱团启示录那些年我们一起
- sip-4.19.zip
- 树莓派3b+学习使用教程
- numpy 中文学习手册
- pytorch-1.4.0-py3.7_cpu_0.tar.bz2
- 机器学习实战 高清完整版PDF
- 车联网大数据可视化展示.rar
- Axure数据可视化图表内含18种图表及其
- 泰坦尼克号0.81准确率实验报告.docx
-
abaqus sc
ripting reference manual.pdf - 网页版聊天程序--网络程序设计课程大
- Give Me Some Credit
-
ba
semap安装出错时,正确得pyproj文件 - 微信头像拼接工具
- 统计思维:程序员数学之概率统计第
- 基于open cv的人脸识别
- Django web 开发中文 完整版本
- 影视领域可视化数据挖掘综述
- pyexiv2安装包
评论
共有 条评论