Search code examples
wolfram-mathematicawolfram-language

Constructing proximity matrix in Wolfram Mathematica


I have the following dataset:

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|>}]

I want to construct proximity matrix out of it, using Euclidean Distance (function in Wolfram Mathematica: EuclideanDistance) between the city populations. I had some trials but it didn't work out in the end. Anyone has an idea?

Thank you in advance!


Solution

  • Try

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

    which I think implements EuclidianDistance