Dendropy interop和numpy数组

时间:2012-11-14 10:22:35

标签: python numpy

我目前正在尝试使用python Dendropy库并在我的代码中包含一些PAUP命令。

我将矩阵作为一个numpy数组,但看起来numpy数组和这个模块存在问题。

***Distance matrix A (Numpy array)***

[[ 0  2  7  8 16 17]
 [ 2  0  5  6 17 16]
 [ 7  5  0  9 15 13]
 [ 8  6  9  0 18 16]
 [16 17 15 18  0  5]
 [17 16 13 16  5  0]]

我尝试使用以下方法将numpy数组转换为numpy矩阵:A=numpy.matrix(A)

import dendropy
from dendropy.interop import paup     

#A is a distance matrix like this    

tree = paup.estimate_tree(A, 'nj')

我得到的错误是:AttributeError: 'matrix' object has no attribute 'write_to_stream'

或:

AttributeError: 'numpy.ndarray' object has no attribute 'write_to_stream'

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

我从未使用过DendroPy,但是从您报告的错误以及快速查看DendroPy文档(例如http://packages.python.org/DendroPy/tutorial/chars.htmlhttp://packages.python.org/DendroPy/tutorial/paup.html){{{{ 1}}期望某种estimate_tree对象(DendroPy中定义的类), NumPy数组或矩阵。