【问题标题】:Dendropy interop and numpy arrayDendropy 互操作和 numpy 数组
【发布时间】:2012-11-14 21:04:23
【问题描述】:

我目前正在尝试使用 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'

任何帮助将不胜感激。

【问题讨论】:

    标签: python numpy


    【解决方案1】:

    我从未使用过DendroPy,但从您报告的错误和快速查看DendroPy 文档(例如http://packages.python.org/DendroPy/tutorial/chars.htmlhttp://packages.python.org/DendroPy/tutorial/paup.html)可以清楚地看出estimate_tree 需要某种@ 987654327@ 对象(DendroPy 中定义的类),不是 NumPy 数组或矩阵。

    【讨论】:

    猜你喜欢
    • 2023-03-17
    • 2016-06-06
    • 2018-11-30
    • 2016-09-30
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    相关资源
    最近更新 更多