2016-10-29 31 views
1

這是我的陣列/ 3維數組列表的輸出(不知道它是哪個),我不明白爲什麼數組數組在那裏,但我希望這不是我的原因無法計算最大值,我通過計算數據集的列之間的皮爾遜r值來獲得此列表。給定一個數組或者三維數組的列表,你如何找到最大值?

[array([[ 1.  , 0.31276108], 
     [ 0.31276108, 1.  ]]), array([[ 1.  , 0.23618345], 
     [ 0.23618345, 1.  ]]), array([[ 1.  , 0.31610011], 
     [ 0.31610011, 1.  ]]), array([[ 1.  , 0.3304167], 
     [ 0.3304167, 1.  ]]), array([[ 1.  , -0.31138519], 
     [-0.31138519, 1.  ]]), array([[ 1.  , 0.49419313], 
     [ 0.49419313, 1.  ]]), array([[ 1.  , 0.49811488], 
     [ 0.49811488, 1.  ]]), array([[ 1.  , 0.39335085], 
     [ 0.39335085, 1.  ]]), array([[ 1.  , -0.44059693], 
     [-0.44059693, 1.  ]]), array([[ 1.  , 0.22362626], 
     [ 0.22362626, 1.  ]]), array([[ 1.  , -0.19201056], 
     [-0.19201056, 1.  ]]), array([[ 1.  , 0.64372004], 
     [ 0.64372004, 1.  ]]), array([[ 1.  , -0.63371678], 
     [-0.63371678, 1.  ]]), array([[ 1.  , 0.56546829], 
     [ 0.56546829, 1.  ]]), array([[ 1.  , -0.42881494], 
     [-0.42881494, 1.  ]]), array([[ 1.  , 0.5190671], 
     [ 0.5190671, 1.  ]]), array([[ 1.  , -0.5032696], 
     [-0.5032696, 1.  ]]), array([[ 1.  , 0.7871939], 
     [ 0.7871939, 1.  ]]), array([[ 1.  , 0.69994936], 
     [ 0.69994936, 1.  ]]), array([[ 1.  , 0.06600394], 
     [ 0.06600394, 1.  ]]), array([[ 1.  , -0.27676855], 
     [-0.27676855, 1.  ]]), array([[ 1.  , 0.00391123], 
     [ 0.00391123, 1.  ]]), array([[ 1.  , -0.36871043], 
     [-0.36871043, 1.  ]]), array([[ 1.  , 0.07234319], 
     [ 0.07234319, 1.  ]]), array([[ 1.  , -0.78822959], 
     [-0.78822959, 1.  ]]), array([[ 1.  , -0.52181319], 
     [-0.52181319, 1.  ]]), array([[ 1.  , 0.29554425], 
     [ 0.29554425, 1.  ]]), array([[ 1.  , -0.26263963], 
     [-0.26263963, 1.  ]]), array([[ 1.  , 0.54347857], 
     [ 0.54347857, 1.  ]]), array([[ 1.  , 0.43368134], 
     [ 0.43368134, 1.  ]]), array([[ 1.  , 0.0553982], 
     [ 0.0553982, 1.  ]]), array([[ 1.  , -0.27395522], 
     [-0.27395522, 1.  ]]), array([[ 1.  , -0.07466689], 
     [-0.07466689, 1.  ]]), array([[ 1.  , -0.56129569], 
     [-0.56129569, 1.  ]]), array([[ 1.  , -0.0717472], 
     [-0.0717472, 1.  ]]), array([[ 1.  , -0.61736921], 
     [-0.61736921, 1.  ]]), array([[ 1.  , -0.02524993], 
     [-0.02524993, 1.  ]]), array([[ 1.  , 0.13905701], 
     [ 0.13905701, 1.  ]]), array([[ 1.  , -0.1723794], 
     [-0.1723794, 1.  ]]), array([[ 1.  , -0.05513642], 
     [-0.05513642, 1.  ]]), array([[ 1.  , 0.19995001], 
     [ 0.19995001, 1.  ]]), array([[ 1.  , 0.01873198], 
     [ 0.01873198, 1.  ]]), array([[ 1.  , 0.25888726], 
     [ 0.25888726, 1.  ]]), array([[ 1.  , 0.24898534], 
     [ 0.24898534, 1.  ]]), array([[ 1.  , 0.5463642], 
     [ 0.5463642, 1.  ]]), array([[ 1.  , 0.26566757], 
     [ 0.26566757, 1.  ]]), array([[ 1.  , -0.3658451], 
     [-0.3658451, 1.  ]]), array([[ 1.  , 0.65269177], 
     [ 0.65269177, 1.  ]]), array([[ 1.  , 0.61241308], 
     [ 0.61241308, 1.  ]]), array([[ 1.  , 0.23644061], 
     [ 0.23644061, 1.  ]]), array([[ 1.  , -0.19732684], 
     [-0.19732684, 1.  ]]), array([[ 1.  , 0.00965194], 
     [ 0.00965194, 1.  ]]), array([[ 1.  , -0.22074619], 
     [-0.22074619, 1.  ]]), array([[ 1.  , 0.13669791], 
     [ 0.13669791, 1.  ]]), array([[ 1.  , -0.49912982], 
     [-0.49912982, 1.  ]]), array([[ 1.  , -0.53789961], 
     [-0.53789961, 1.  ]]), array([[ 1.  , -0.4499353], 
     [-0.4499353, 1.  ]]), array([[ 1.  , -0.25629405], 
     [-0.25629405, 1.  ]]), array([[ 1.  , 0.36192172], 
     [ 0.36192172, 1.  ]]), array([[ 1.  , 0.18623045], 
     [ 0.18623045, 1.  ]]), array([[ 1.  , 0.29297713], 
     [ 0.29297713, 1.  ]]), array([[ 1.  , -0.15592947], 
     [-0.15592947, 1.  ]]), array([[ 1.  , 0.48910916], 
     [ 0.48910916, 1.  ]]), array([[ 1.  , 0.8645635], 
     [ 0.8645635, 1.  ]]), array([[ 1.  , 0.19578377], 
     [ 0.19578377, 1.  ]]), array([[ 1.  , -0.35136986], 
     [-0.35136986, 1.  ]]), array([[ 1.  , 0.11507728], 
     [ 0.11507728, 1.  ]]), array([[ 1.  , -0.41100659], 
     [-0.41100659, 1.  ]]), array([[ 1.  , 0.23681493], 
     [ 0.23681493, 1.  ]]), array([[ 1.  , -0.84749754], 
     [-0.84749754, 1.  ]]), array([[ 1.  , 0.21440123], 
     [ 0.21440123, 1.  ]]), array([[ 1.  , -0.32111332], 
     [-0.32111332, 1.  ]]), array([[ 1.  , 0.12897954], 
     [ 0.12897954, 1.  ]]), array([[ 1.  , -0.335167], 
     [-0.335167, 1.  ]]), array([[ 1.  , 0.28910112], 
     [ 0.28910112, 1.  ]]), array([[ 1.  , -0.71916334], 
     [-0.71916334, 1.  ]]), array([[ 1.  , -0.08333309], 
     [-0.08333309, 1.  ]]), array([[ 1.  , 0.28658669], 
     [ 0.28658669, 1.  ]]), array([[ 1.  , -0.0545751], 
     [-0.0545751, 1.  ]]), array([[ 1.  , 0.27079823], 
     [ 0.27079823, 1.  ]]), array([[ 1.  , -0.20917939], 
     [-0.20917939, 1.  ]]), array([[ 1.  , 0.44336719], 
     [ 0.44336719, 1.  ]]), array([[ 1.  , 0.2885004], 
     [ 0.2885004, 1.  ]]), array([[ 1.  , -0.31023514], 
     [-0.31023514, 1.  ]]), array([[ 1.  , 0.51785911], 
     [ 0.51785911, 1.  ]]), array([[ 1.  , 0.16404547], 
     [ 0.16404547, 1.  ]]), array([[ 1.  , 0.2115446], 
     [ 0.2115446, 1.  ]]), array([[ 1.  , -0.04964322], 
     [-0.04964322, 1.  ]]), array([[ 1.  , 0.09439694], 
     [ 0.09439694, 1.  ]]), array([[ 1.  , 0.4377762], 
     [ 0.4377762, 1.  ]]), array([[ 1.  , -0.32822194], 
     [-0.32822194, 1.  ]])] 

這裏是我求最大值的代碼,

for i in range(len(r)): 
    for j in range(len(r)): 
     if r[i][1][0]==r[j][1][0]: 
      data=r[i][1][0] 
     elif r[i][1][0] < r[j][1][0]: 
      data=r[j][1][0] 
     else: 
     data=r[i][1][0] 

,這是給我的-0.328的輸出,其中通過檢查很明顯的最大值是0.79

+0

最大值爲1 ... –

+0

哎呀,1是所有矩陣無關,我只是在看值的範圍之外的對角線單個2x2矩陣 – user5896534

+0

我用過np.amax(),但1不是我想要的值 – user5896534

回答

0

我懷疑無論如何導致你陷入混亂狀態並不是嘗試實現你正在做的任何事情的最佳方式。但是,假設你的2x2陣列的名單a,你知道一個給定的2×2陣列的antidiagonal的值是相同的,那麼你可以簡單地做:

max(arr[0,1] for arr in a) 

如果你不知道他們總是相等的,那麼你可以使用這樣的事情:

max(np.flipud(arr).diagonal().max() for arr in a) 
+0

謝謝你,這使我的計算方式更容易 – user5896534

相關問題