当前位置: 首页 > news >正文

宁波公司核名网站推广文章

宁波公司核名网站,推广文章,wordpress 数卡,网站建设英文版参考1 自定义输入矩阵来绘制 根据参考代码, 自定义 代码如下: # 编程实现有向图连通性的判断 from pylab import mplmpl.rcParams[font.sans-serif] [SimHei] mpl.rcParams[axes.unicode_minus] False import numpy as np import networkx as nx imp…

参考1
自定义输入矩阵来绘制

根据参考代码,
自定义
代码如下:

# 编程实现有向图连通性的判断
from pylab import mplmpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
import pylab#定义x三阶矩阵
x = np.array([[1, 0, 0], [1, 1, 0], [1, 1, 1]])#随机生成x为五阶矩阵
# x = np.random.randint(0, 2, (5, 5))
n = len(x)value_1 = value_2 = sum_1 = sum_2 = sum_3 = sum_4 = y = final = x
y = x + x.T# 计算可达矩阵
for i in range(1, n):value_1 = np.matmul(value_1, x)sum_1 = sum_1 + value_1
sum_2 = sum_1 + np.identity(n)reachability_matrix = sum_2 > 0.5print("此有向图的可达矩阵为:")
print(reachability_matrix.astype(int))final = reachability_matrix + reachability_matrix.Tfor i in range(1, n):value_2 = np.matmul(value_2, y)sum_3 = sum_3 + value_2
sum_4 = sum_3 + np.identity(n)
reachability_matrix_1 = sum_4 > 0.5# 给出判断结果
if ((reachability_matrix.astype(int) == np.ones((n, n)).astype(int)).all()):print("此有向线图G为强连通图或其为无向连通图")
elif ((final.astype(int) == np.ones((n, n)).astype(int)).all()):print("此有向线图G是单向连通图")
elif ((reachability_matrix_1.astype(int) == np.ones((n, n)).astype(int)).all()):print("此有向线图G是弱连通图")
else:print("此有向图不连通")# 下面展示图形化输出有向图G
G = nx.DiGraph()
for i in range(0, n):j=i+1G.add_node(i, desc='p' + str(j))for p in range(0, n):for q in range(0, n):if x[p, q] == 1:G.add_edges_from([(p, q)], weight='1')edge_labels = dict([((u, v), d['weight']) for u, v, d in G.edges(data=True)])
edge_colors = ['black']
pos = nx.spring_layout(G)
node_labels = nx.get_node_attributes(G, 'desc')
nx.draw_networkx_labels(G, pos, labels=node_labels)
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)
nx.draw(G, pos, node_size=1500, edge_color=edge_colors, edge_cmap=plt.cm.Reds)
plt.title('Directed Graph', fontsize=10)
pylab.show()

第二版

增大了字体
可以自定义字体大小

# 编程实现有向图连通性的判断
from pylab import mplmpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
import pylab#定义x三阶矩阵
x = np.array([[1, 0, 0], [1, 1, 0], [1, 1, 1]])#随机生成x为五阶矩阵
# x = np.random.randint(0, 2, (5, 5))
n = len(x)value_1 = value_2 = sum_1 = sum_2 = sum_3 = sum_4 = y = final = x
y = x + x.T# 计算可达矩阵
for i in range(1, n):value_1 = np.matmul(value_1, x)sum_1 = sum_1 + value_1
sum_2 = sum_1 + np.identity(n)reachability_matrix = sum_2 > 0.5print("此有向图的可达矩阵为:")
print(reachability_matrix.astype(int))final = reachability_matrix + reachability_matrix.Tfor i in range(1, n):value_2 = np.matmul(value_2, y)sum_3 = sum_3 + value_2
sum_4 = sum_3 + np.identity(n)
reachability_matrix_1 = sum_4 > 0.5# 给出判断结果
if ((reachability_matrix.astype(int) == np.ones((n, n)).astype(int)).all()):print("此有向线图G为强连通图或其为无向连通图")
elif ((final.astype(int) == np.ones((n, n)).astype(int)).all()):print("此有向线图G是单向连通图")
elif ((reachability_matrix_1.astype(int) == np.ones((n, n)).astype(int)).all()):print("此有向线图G是弱连通图")
else:print("此有向图不连通")# 下面展示图形化输出有向图G
G = nx.DiGraph()
for i in range(0, n):j = i + 1G.add_node(i, desc='p' + str(j))for p in range(0, n):for q in range(0, n):if x[p, q] == 1:G.add_edges_from([(p, q)], weight='1')edge_labels = dict([((u, v), d['weight']) for u, v, d in G.edges(data=True)])
edge_colors = ['black']
pos = nx.spring_layout(G)
node_labels = nx.get_node_attributes(G, 'desc')
nx.draw_networkx_labels(G, pos, labels=node_labels, font_size=16)  # 设置字体大小为16nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=12)nx.draw(G, pos, node_size=1500, edge_color=edge_colors, edge_cmap=plt.cm.Reds)
plt.title('Directed Graph', fontsize=10)
pylab.show()
http://www.mmbaike.com/news/32885.html

相关文章:

  • 视频网站如何推广东方网络律师团队
  • 网站发产品ps怎么做产品图windows优化大师在哪里
  • 云购网站做的起来吗seo单页面优化
  • 网站后台不能粘贴广州疫情升级
  • 品牌网站建设 2蝌蚪小如何做到精准客户推广
  • 提供郑州网站建设网络营销和市场营销的区别
  • 红色企业网站源码网络营销是学什么的
  • 游戏网站策划书seo费用
  • 潮州疫情最新消息十堰seo优化
  • 建立学校网站网络营销与策划
  • 信誉好的福州网站建设武汉网站营销seo方案
  • 有做soho网站的吗江西seo
  • 广东网站备案需要多久广州网站优化平台
  • 成品网站qq客服seo点击排名软件营销工具
  • 做网站商武汉百度推广公司
  • app制作平台收费标准seo培训优化课程
  • 做彩票网站犯法不域名查询 站长查询
  • 如何在导航网站上做链接dsp投放方式
  • 外国炫酷网站网址昆明seo关键字推广
  • 杭州做卖房子的工作哪个网站好网站的推广
  • 品牌型 网站建设seo排名技巧
  • 咸宁做网站公司互联网推广销售好做吗
  • 做网站目的推广信息怎么写
  • 做创新方法工作网站互联网广告优势
  • 做网站的人 优帮云百度图片识别在线识图
  • 荆州网站建设 众火网惠州百度seo排名
  • 如何查询网站打开速度免费b站网页推广
  • 自己做网站要哪些东西做搜索引擎优化的企业
  • 建立网站导航栏的方法我想做电商
  • 最新新闻热点事件国际好的seo公司营销网