2013-04-10 35 views
1

我在下面定製的N×N的距離矩陣numpy的/ SciPy的:送入距離矩陣與R集羣從Rpy2

dist_matrix = array([array([5, 4, 2, 3, 2, 3]), 
         array([4, 5, 2, 3, 2, 2]), 
         array([2, 2, 5, 2, 2, 1]), 
         array([3, 3, 2, 5, 4, 2]), 
         array([2, 2, 2, 4, 5, 1]), 
         array([3, 2, 1, 2, 1, 5])]) 

我如何使用這個矩陣做聚類和情節樹狀圖中R/GGPLOT2?如果我嘗試通過rpy2這個距離矩陣送入R作爲:

r.hclust(dist_matrix) 

我得到的錯誤:

res = super(Function, self).__call__(*new_args, **new_kwargs) 
rpy2.rinterface.RRuntimeError: Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") : 
    missing value where TRUE/FALSE needed 
+0

是'dist_matrix'是一個NxN數組,還是它是1d數組的形狀爲'(N,)'和dtype'object'的1d數組,因爲它似乎顯示? – askewchan 2013-04-10 19:59:59

+0

@askewchan:我可以用任何一種格式製作它......我嘗試了兩種方法並得到錯誤...但無論如何,我可以在兩者之間來回切換 – user248237dfsf 2013-04-10 22:13:25

回答

1

R函數hclust()正在 「距離」 的對象:

from rpy2.robjects.packages import importr 
stats = importr("stats") 
d = stats.as_dist(m) 
hc = r.hclust(d) 

[注意:錯誤信息也暗示了rpy2中可能的轉換錯誤。你能提交一份錯誤報告嗎?謝謝]