当节点不在图中时,我得到异常错误。当我试图抓住并处理它时,我不能(所以我一定是做错了什么)。我如何捕捉和处理networkx.exception.NetworkXError?
这是错误:
<snip>
raise NetworkXError("The node %s is not in the digraph."%(n,))
networkx.exception.NetworkXError: The node 33293542 is not in the digraph.
这是我试图捕捉并处理它的方法:
try:
path_len = nx.shortest_path_length(G,uNode, vNode)
except (nx.NetworkXNoPath, nx.exception.NetworkXError) as e:
print e
continue
Run Code Online (Sandbox Code Playgroud)
我也试过:
try:
path_len = nx.shortest_path_length(G,uNode, vNode)
except (nx.NetworkXNoPath, KeyError) as e:
print e
continue
Run Code Online (Sandbox Code Playgroud)
我维护uNode并vNode在两个列表中,我可以做一个:if v in target_nodes:,但在我这样做之前,我想知道是否有一种优雅的方法来处理这个NetworkX exception?
构建一个提升图,其中添加的边缘区域(如下)和 v1 被定义为
gm->create_edge(v1,v2,1);
boost::graph_traits<Graph>::vertex_descriptor v1 = gm-> create_vertex("one",1,1);
Run Code Online (Sandbox Code Playgroud)
如何打印或枚举顶点使用?:
boost::graph_traits<Graph>::vertex_descriptor vd;
Run Code Online (Sandbox Code Playgroud)
这允许我打印顶点 ID:
Graph::vertex_iterator v, vend, vnext;
for (boost::tie(v, vend) = vertices(gm->g); v != vend; ++v)
std::cout << gm->g[*v].id << ", " << gm->g[*v].color << ", ";
Run Code Online (Sandbox Code Playgroud)
我有一个关于节点度数的函数,它需要一个顶点描述符,那么,我该如何传递呢?
gm->degree( takes vertex_descriptor )?
Run Code Online (Sandbox Code Playgroud)
这个链接很近。
使用AVCam示例,我看不到如何访问AVCamViewController.m文件中的图像.我想预览捕获的图像,但我不知道如何在方法中访问此图像:- (IBAction)captureStillImage:(id)sender在行之后:[[self captureManager] captureStillImage];
我想以编程方式添加预览,如下所示:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320/5, 480/5)];
[imageView setImage:[captureManager image]];
[self.view addSubview:imageView];
[imageView release];
Run Code Online (Sandbox Code Playgroud)
我试图在这里找到帮助,但一直没能.这里有人有一些提示吗?