TypeError: Only length-1 arrays can be converted to Python scalars

 #p1Vect也是一个向量
    p1Vect = math.log(p1Num / p1Denom)
    p0Vect = math.log(p0Num / p0Denom)

报错如下:

TypeError: Only length-1 arrays can be converted to Python scalars

原因:

math.log()不能直接处理矩阵

resolution:

  #p1Vect也是一个向量
    p1Vect = [math.log(x) for x in (p1Num / p1Denom)]
    p0Vect = [math.log(x) for x in (p0Num / p0Denom)]
欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
原文地址:https://www.cnblogs.com/flyingcr/p/10326862.html