braycurtis相异矩阵(numpy array)结果中的一些元素包含' nan'

时间:2015-11-25 05:05:38

标签: python-3.x numpy scipy

我为下面的矩阵计算了braycurtis相异矩阵。行是社区,列是物种

[[  0   0   0   0]
 [ 13 110   0   0]
 [  6   3   0   0]
 [  0   5   0   0]
 [  0 128   0   0]
 [  0   0   0   0]
 [ 11  76  11   0]
 [  8  29   3   0]
 [  0  58   5   0]
 [  1   3   0   0]
 [  4  11   1   0]
 [  3  38   0   0]
 [  9  35   8   7]
 [  0   0   0   0]
 [  0   0   0   0]
 [ 63 576  11   9]
 [ 24  99   0   0]
 [  1  29   5   0]
 [  0   0   0   0]
 [  0   0   0   0]
 [  0   0   0   0]
 [  0   0   0   0]
 [  2   0   0   0]
 [  1   4   0   0]
 [  0   0   0   0]
 [  8  20   0   0]
 [  3  21  13   6]
 [  1   4   0   0]
 [  0   0   0   0]
 [  0   0   0   0]
 [  0   4   0   0]]

我用过

dissimilarityMatrix=scipy.spatial.distance.pdist(CommGrouped, 'braycurtis')

并得到以下结果

[ 1.          1.          1.          1.                 nan  1.          1.
  1.          1.          1.          1.          1.                 nan
         nan  1.          1.          1.                 nan         nan
         nan         nan  1.          1.                 nan  1.          1.
  1.                 nan         nan  1.          0.86363636  0.921875
  0.12350598  1.          0.21266968  0.54601227  0.37634409  0.93700787
  0.78417266  0.5         0.51648352  1.          1.          0.68542199
  0.08943089  0.62025316  1.          1.          1.          1.          0.968
  0.921875    1.          0.62913907  0.71084337  0.921875    1.          1.
  0.93700787  0.57142857  0.95620438  1.          0.8317757   0.63265306
  0.91666667  0.38461538  0.44        0.76        0.73529412  1.          1.
  0.97305389  0.86363636  0.81818182  1.          1.          1.          1.
  0.63636364  0.42857143  1.          0.51351351  0.76923077  0.42857143
  1.          1.          0.53846154  0.92481203  1.          0.90291262
  0.77777778  0.85294118  0.33333333  0.52380952  0.7826087   0.84375     1.
  1.          0.98493976  0.921875    0.75        1.          1.          1.
  1.          1.          0.2         1.          0.6969697   0.79166667
  0.2         1.          1.          0.11111111  1.          0.32743363
  0.6547619   0.39267016  0.95454545  0.84722222  0.55029586  0.62566845
  1.          1.          0.6747141   0.21115538  0.64417178  1.          1.
  1.          1.          1.          0.93984962  1.          0.74358974
  0.75438596  0.93984962  1.          1.          0.93939394  1.          1.
  1.          1.          1.          1.          1.                 nan
         nan  1.          1.          1.                 nan         nan
         nan         nan  1.          1.                 nan  1.          1.
  1.                 nan         nan  1.          0.42028986  0.2173913
  0.92156863  0.71929825  0.41007194  0.33757962  1.          1.
  0.74108322  0.21266968  0.47368421  1.          1.          1.          1.
  0.96        0.90291262  1.          0.55555556  0.5035461   0.90291262
  1.          1.          0.92156863  0.37864078  0.81818182  0.42857143
  0.20987654  0.19191919  1.          1.          0.88555079  0.54601227
  0.12        1.          1.          1.          1.          0.9047619
  0.77777778  1.          0.17647059  0.34939759  0.77777778  1.          1.
  0.81818182  0.91044776  0.69620253  0.26923077  0.3442623   1.          1.
  0.82548476  0.37634409  0.30612245  1.          1.          1.          1.
  1.          0.88235294  1.          0.56043956  0.50943396  0.88235294
  1.          1.          0.88059701  0.6         0.82222222  0.87301587
  1.          1.          0.98793363  0.93700787  0.79487179  1.          1.
  1.          1.          0.66666667  0.11111111  1.          0.75
  0.82978723  0.11111111  1.          1.          0.25        0.50877193
  0.57333333  1.          1.          0.95259259  0.78417266  0.49019608
  1.          1.          1.          1.          0.77777778  0.52380952
  1.          0.31818182  0.49152542  0.52380952  1.          1.          0.6
  0.24        1.          1.          0.88285714  0.5         0.21052632
  1.          1.          1.          1.          0.90697674  0.7826087   1.
  0.33333333  0.42857143  0.7826087   1.          1.          0.82222222
  1.          1.          0.8356546   0.51648352  0.25531915  1.          1.
  1.          1.          0.93442623  0.84375     1.          0.35632184
  0.25490196  0.84375     1.          1.          0.87301587         nan
  1.          1.          1.                 nan         nan         nan
         nan  1.          1.                 nan  1.          1.          1.
         nan         nan  1.          1.          1.          1.
         nan         nan         nan         nan  1.          1.
         nan  1.          1.          1.                 nan         nan
  1.          0.68542199  0.89913545  1.          1.          1.          1.
  0.99394856  0.98493976  1.          0.91848617  0.88319088  0.98493976
  1.          1.          0.98793363  0.62025316  1.          1.          1.
  1.          0.968       0.921875    1.          0.62913907  0.71084337
  0.921875    1.          1.          0.93700787  1.          1.          1.
  1.          0.94594595  0.75        1.          0.33333333  0.30769231
  0.75        1.          1.          0.79487179         nan         nan
         nan  1.          1.                 nan  1.          1.          1.
         nan         nan  1.                 nan         nan  1.          1.
         nan  1.          1.          1.                 nan         nan
  1.                 nan  1.          1.                 nan  1.          1.
  1.                 nan         nan  1.          1.          1.
         nan  1.          1.          1.                 nan         nan
  1.          0.71428571  1.          0.86666667  0.91111111  0.71428571
  1.          1.          1.          1.          0.6969697   0.79166667
  0.          1.          1.          0.11111111  1.          1.          1.
         nan         nan  1.          0.35211268  0.6969697   1.          1.
  0.75        0.79166667  1.          1.          0.82978723  1.          1.
  0.11111111         nan  1.          1.        ]

我无法弄清楚结果是否正确以及获得纳米的原因。

请帮忙!

1 个答案:

答案 0 :(得分:0)

是的,输出正确。

很容易验证自己:documentation on pdist具有Bray-Curtis距离的实际公式:

  

d(u,v)=Σ i (u i - v i )/Σ i (你 i + v i

因此,您可以自己计算所有距离(或者只需要检查一些距离)。

NaNs也很明显:它们是分子和分母都为0的结果,这对于输入中的一堆矢量组合会发生。