【问题标题】:Constructing proximity matrix in Wolfram Mathematica在 Wolfram Mathematica 中构造邻近矩阵
【发布时间】:2021-08-05 16:24:24
【问题描述】:

我有以下数据集:

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)从中构建邻近矩阵。我进行了一些尝试,但最终没有成功。有人有想法吗?

提前谢谢你!

【问题讨论】:

    标签: wolfram-mathematica wolfram-language


    【解决方案1】:

    试试

    pop=Normal[dataset[All,"Population"]];
    MatrixPlot[Outer[Sqrt[(#1-#2)^2]&,pop,pop]]
    

    我认为它实现了 EuclidianDistance

    【讨论】:

      【解决方案2】:

      添加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]
      

      【讨论】:

        猜你喜欢
        • 2011-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多