首页 > 解决方案 > 输入类型不支持 ufunc 'bitwise_or'

问题描述

我正在尝试根据以下等式制作“matplotlib”图:q(x) = (x**2) / (x+1)

我试过这段代码:


def r(x):
    return (x*x) / (x+1)

while x<= -2 | x >= 0:
    pylab.plot(x, r(x), color = 'r--')

这向我显示了错误:


TypeError                                 Traceback (most recent call last)
<ipython-input-14-387fb2375bb1> in <module>
      2     return (x*x) / (x+1)
      3 
----> 4 while x<= -2 | x >= 0:
      5     pylab.plot(x, r(x), color = 'r--')

TypeError: ufunc 'bitwise_or' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

我是使用 python 进行机器学习的新手,所以我对如何调试它知之甚少。

谢谢你的帮助!

标签: pythonmachine-learningbitwise-operators

解决方案


|是按位或运算符 - 您应该使用简单or的关键字作为逻辑替代。

进一步阅读


推荐阅读