s = np.array([[35788, 41715, ... 34964],
[5047, 23529, ... 5165],
[12104, 33899, ... 11914],
[3646, 21031, ... 3814],
[8704, 7906, ... 8705]])
我有這樣
end =[]
for i in range(len(s)):
for j in range(i, len(s)):
out = mahalanobis(s[i], s[j], invcov)
end.append(out)
print end
一個循環,我把輸出:
[0.0, 12.99, 5.85, 10.22, 3.95, 0.0, 5.12, 3.45, 4.10, 0.0, 5.05, 8.10, 0.0, 15.45, 0.0]
但我想像這樣的輸出:
[[0.0, 12.99, 5.85, 10.22, 3.95],
[12.99, 0.0, 5.12, 3.45, 4.10],
[5.85, 5.12, 0.0, 5.05, 8.10],
[10.22, 3.45, 5.05, 0.0, 15.45],
[3.95, 4.10, 8.10, 15.45, 0.0]]
要澄清,你想要一個清單,每個清單包含5個項目?或者內部列表的大小會有所不同? – Banjer 2015-04-01 01:17:09
我想要一個列表,每個列表包含正好5個項目,就像距離矩陣 – 2015-04-01 01:20:34