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)]

 

转载于:https://www.cnblogs.com/flyingcr/p/10326862.html

你可能感兴趣的:(TypeError: Only length-1 arrays can be converted to Python scalars)