在 Wolfram Mathematica 中构造邻近矩阵
Constructing proximity matrix in Wolfram Mathematica
我有以下数据集:
dataset =
Dataset[{<|"City" -> "Belgrade" , "Population" -> 1500000|>, <|
"City" -> "Ljubljana", "Population" -> 300000|>, <|
"City" -> "Sarajevo", "Population" -> 275000|>, <|
"City" -> "Zagreb", "Population" -> 800000|>, <|
"City" -> "Skopje", "Population" -> 530000|>, <|
"City" -> "Podgorica", "Population" -> 180000|>}]
我想利用城市人口之间的欧氏距离(Wolfram Mathematica 中的函数:EuclideanDistance)从中构建邻近矩阵。我进行了一些试验,但最终没有成功。有人有想法吗?
提前致谢!
尝试
pop=Normal[dataset[All,"Population"]];
MatrixPlot[Outer[Sqrt[(#1-#2)^2]&,pop,pop]]
我认为它实现了 EuclidianDistance
添加 FrameTicks
并使用 EuclideanDistance
。
pop = Normal[dataset[All, "Population"]];
cities = Normal[dataset[All, "City"]];
ticks = List @@@ Thread[Range@Length@cities -> (Style[#, 14, Black] &) /@ cities]
MatrixPlot[Outer[EuclideanDistance[##] &, pop, pop],
FrameTicks -> {ticks, ticks, ticks, ticks},
Mesh -> True,
MeshStyle -> Black,
ImageSize -> 600]
我有以下数据集:
dataset =
Dataset[{<|"City" -> "Belgrade" , "Population" -> 1500000|>, <|
"City" -> "Ljubljana", "Population" -> 300000|>, <|
"City" -> "Sarajevo", "Population" -> 275000|>, <|
"City" -> "Zagreb", "Population" -> 800000|>, <|
"City" -> "Skopje", "Population" -> 530000|>, <|
"City" -> "Podgorica", "Population" -> 180000|>}]
我想利用城市人口之间的欧氏距离(Wolfram Mathematica 中的函数:EuclideanDistance)从中构建邻近矩阵。我进行了一些试验,但最终没有成功。有人有想法吗?
提前致谢!
尝试
pop=Normal[dataset[All,"Population"]];
MatrixPlot[Outer[Sqrt[(#1-#2)^2]&,pop,pop]]
我认为它实现了 EuclidianDistance
添加 FrameTicks
并使用 EuclideanDistance
。
pop = Normal[dataset[All, "Population"]];
cities = Normal[dataset[All, "City"]];
ticks = List @@@ Thread[Range@Length@cities -> (Style[#, 14, Black] &) /@ cities]
MatrixPlot[Outer[EuclideanDistance[##] &, pop, pop],
FrameTicks -> {ticks, ticks, ticks, ticks},
Mesh -> True,
MeshStyle -> Black,
ImageSize -> 600]