Wolfram 语言

图像和信号处理

比较芝加哥和欧洲首府城市的天气

找出去年与芝加哥的气温最接近的欧盟首府城市. 使用 WarpingDistance 来确定温度序列间的相似度.

In[1]:=
Click for copyable input
chicagoTemp = WeatherData["Chicago", "Temperature", {{2015, 7}, {2016, 6}, "Week"}, "Value"];

获取所有欧盟首府城市的气温.

In[2]:=
Click for copyable input
capitals = CityData /@ CountryData["EU", "CapitalCity"] // Sort
Out[2]=
In[3]:=
Click for copyable input
capitalsTemp = WeatherData[#, "Temperature", {{2015, 7}, {2016, 6}, "Week"}, "Value"] -> # & /@ capitals;

找出与芝加哥气温最接近的首府城市.

In[4]:=
Click for copyable input
Nearest[capitalsTemp, chicagoTemp, DistanceFunction -> (QuantityMagnitude@WarpingDistance[##] &)]
Out[4]=

在一个矩阵中计算两两之间的距离.

In[5]:=
Click for copyable input
dm = DistanceMatrix[Keys@capitalsTemp, DistanceFunction -> (QuantityMagnitude@WarpingDistance[##] &)];

显示距离矩阵的 7×7 子矩阵.

In[6]:=
Click for copyable input
MatrixForm[Take[dm, 7, 7]]
Out[6]//MatrixForm=

利用之前计算过的距离矩阵可视化温度的相似度.

显示完整的 Wolfram 语言输入
In[7]:=
Click for copyable input
MatrixPlot[dm, FrameTicks -> {{Transpose[{Range[Length@capitals], capitals}], None}, {Transpose[{Range[Length@capitals], Rotate[#, \[Pi]/2] & /@ capitals}], None}}, Mesh -> True, ColorFunction -> "BlueGreenYellow", PlotLegends -> Placed[Automatic, Above], PlotLabel -> "Distance based on temperature", ImageSize -> Large]
Out[7]=

相关范例

de en es fr ja ko pt-br ru