Python 无法在SageMath中将numpy数组转换为图形
按照说明下载Python 无法在SageMath中将numpy数组转换为图形,python,numpy,scipy,ipython,sage,Python,Numpy,Scipy,Ipython,Sage,按照说明下载testnb.sws后 在网站上 我试着在传统的“圣人笔记本”中运行它 (不是Jupyter笔记本),如下所示: 打开Sage笔记本 点击“上传” 单击“浏览” 选择testnb.sws 单击“上载工作表” 单击“评估” 计算此工作表中的代码单元格将导致 以下错误: ValueError: This input cannot be turned into a graph 似乎在Sage中,np.array()是无效的 然而,当我使用 Aij32 = ([[0,1,0],[1
testnb.sws
后
在网站上我试着在传统的“圣人笔记本”中运行它 (不是Jupyter笔记本),如下所示:
- 打开Sage笔记本
- 点击“上传”
- 单击“浏览”
- 选择
testnb.sws
- 单击“上载工作表”
- 单击“评估”
计算此工作表中的代码单元格将导致 以下错误:
ValueError: This input cannot be turned into a graph
似乎在Sage中,np.array()是无效的
然而,当我使用
Aij32 = ([[0,1,0],[1,0,1],[0,1,0]])
而不是
Aij32 = np.array([[0,1,0],[1,0,1],[0,1,0]])
它表明
AttributeError: 'list' object has no attribute 'copy'
如何克服这个问题?将numpy数组转换为图形
如果a
是表示邻接矩阵的numpy数组
对于图形,则代替
Graph(a)
可以使用
Graph(matrix(a))
建立相应的图形
修正问题中提到的工作表
在问题中提到的工作表testnb.sws
中,
更换此块
# get clusters
print "the orbits are:"
print data32.get_orbits()
在下面的街区
def get_orbits(a):
r"""
Return the orbits as a list of lists
"""
if a._orbits is None:
a._group, a._orbits = sg.Graph(
matrix(a.get_adjacency_matrix())
).automorphism_group(orbits=True)
return sg.copy(a._orbits)
# get clusters
print "the orbits are:"
print get_orbits(data32)
让一切都很顺利。太棒了!谢谢