本文整理汇总了Python中sage.graphs.all.DiGraph.__getitem__方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.__getitem__方法的具体用法?Python DiGraph.__getitem__怎么用?Python DiGraph.__getitem__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.all.DiGraph
的用法示例。
在下文中一共展示了DiGraph.__getitem__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __getitem__
# 需要导入模块: from sage.graphs.all import DiGraph [as 别名]
# 或者: from sage.graphs.all.DiGraph import __getitem__ [as 别名]
def __getitem__(self, i):
r"""
With a tuple (i,j) as argument, returns the scalar product
`\langle
\alpha^\vee_i, \alpha_j\rangle`.
Otherwise, behaves as the usual DiGraph.__getitem__
EXAMPLES: We use the `C_4` dynkin diagram as a cartan
matrix::
sage: g = DynkinDiagram(['C',4])
sage: matrix([[g[i,j] for j in range(1,5)] for i in range(1,5)])
[ 2 -1 0 0]
[-1 2 -1 0]
[ 0 -1 2 -2]
[ 0 0 -1 2]
The neighbors of a node can still be obtained in the usual way::
sage: [g[i] for i in range(1,5)]
[[2], [1, 3], [2, 4], [3]]
"""
if not isinstance(i, tuple):
return DiGraph.__getitem__(self, i)
[i, j] = i
if i == j:
return 2
elif self.has_edge(j, i):
return -self.edge_label(j, i)
else:
return 0