小编Wor*_*rse的帖子

使用igraph/R查找所有最短路径

首先,我对R不是很精通,但我有一个100个节点的网络,我正在做分析.我想找到网络中每对节点之间的所有最短路径(100次计算),诀窍是将它们作为整数返回,路径长度如果你愿意的话.

#construct a small sample of the graph
g = graph.formula('insert graph') 

#use the function to retrieve shortest paths from a single vertex
get.all.shortest.paths(g, 1, to = V(g))

#output
$res
$res[[1]]
[1] 1

$res[[2]]
[1] 1 2

$res[[3]]
[1] 1 2 3

$res[[4]]
[1] 1 2 3 4

$res[[5]]
[1] 1 2 3 4 5

$res[[6]]
[1]  1 10  9  8  7  6

$res[[7]]
[1] 1 2 3 4 5 6

$res[[8]]
[1]  1 10  9  8  7

$res[[9]]
[1] …
Run Code Online (Sandbox Code Playgroud)

r graph igraph

7
推荐指数
1
解决办法
1万
查看次数

Networkx中的图论

我现在开始使用这个界面,我有一些Python的经验但没什么广泛的.我正在计算一个小图的传递性和社区结构:

import networkx as nx

G = nx.read_edgelist(data, delimiter='-', nodetype=str)
nx.transitivity(G)

#find modularity
part = best_partition(G)
modularity(part, G)
Run Code Online (Sandbox Code Playgroud)

我得到了传递性,但是 - 计算模块性存在以下错误.

NameError: name 'best_partition' is not defined
Run Code Online (Sandbox Code Playgroud)

我只是按照networkx网站提供的文档,有什么我做错了吗?

python graph networkx

5
推荐指数
1
解决办法
2801
查看次数

计算任意数量的词典中最常见的值

我有数百个看起来像这样的词典.它们都有相同的键(纽约,芝加哥等......)但具有不同的值.没有遗漏的值.

[{'New York': 'cloudy', 'Chicago': 'snowy', 'Seattle': 'rainy'},
 {'New York': 'cloudy', 'Chicago': 'hailing', 'Seattle': 'sunny'},
 {'New York': 'sunny', 'Chicago': 'snowy', 'Seattle': 'rainy'}, 
 {'New York': 'hailing', 'Chicago': 'snowy', 'Seattle':'snowy'}]
Run Code Online (Sandbox Code Playgroud)

我想计算每个键最常见的"天气"值.然后将它们全部合并到一个最终列表中,该列表仅输出具有其最常见键值的每个城市.

{'New York': 'cloudy', 'Chicago': 'snowy', 'Seattle': 'rainy'}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

python python-3.x

2
推荐指数
1
解决办法
32
查看次数

在 R 中将数字转换为字符串,同时保持字符不变

我有一个如下所示的向量:

> vector <- c("1","2","0", "10", "name", "hello")
Run Code Online (Sandbox Code Playgroud)

我想将其转换为每个数字字符变成一个字符串,而不影响实际的字符串。

[1] "test" "test" "test" "test" "name" "hello"
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

r

1
推荐指数
1
解决办法
41
查看次数

标签 统计

graph ×2

python ×2

r ×2

igraph ×1

networkx ×1

python-3.x ×1