python - 输入类型不支持 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 进行机器学习的新手,所以我对如何调试它知之甚少。
谢谢你的帮助!
解决方案
|
是按位或运算符 - 您应该使用简单or
的关键字作为逻辑替代。
推荐阅读
- mysql - 我无法在 MySQL Workbench 中声明变量
- python - 数据插入数据库后发出 Socket 事件
- r - R tidyr::unite 如何防止空白列被删除?
- mongodb - -Spark Scala Mongodb- MongoTypeConversionException 无法将 STRING 转换为 StructType(...)
- vba - 打开用户窗体时隐藏组合框
- next.js - 首次使用 Next-Auth 创建用户时如何实例化模型?
- javascript - 查找辅助y轴的宽度
- python - df.plot.scatter: c 和 cmap
- java - DefaultUnitOfWork.reset() api 调用后未调用 Apache Camel MDC Logging - camel 3.10
- java - Eclipse 和 Maven:启动层初始化期间发生错误