python - python中这种运算符组合有什么用,"\| “?
问题描述
好吧,我跑了一段代码,但我无法弄清楚它的功能。它是这样的:
thresholds = (image[:,:,0] < rgbThreshold[0]) \
| (image[:,:,1] < rgbThreshold[1]) \
| (image[:,:,2] < rgbThreshold[2])
就在那边,
\ <"返回"> | (图像[:,:,1] < ....
我不太清楚它的作用。
如果有人想知道这段代码是做什么的,这里有一组 RGB 阈值(redThreshold、green....)和一个图像“图像”。
我只是选择低于指定阈值的所有像素。然后我通过将它们colorSelect[threshold] = [0,0,0]
变黑来访问它们(colorSelect 是一个 numpy 数组,它通过其 RBG 像素值表示图像。)
解决方案
|
表示or
并且\
仅用于使下一行的内容符合 PEP-8 指南,并且用户能够以这种方式更好地阅读代码。
这里:
thresholds = (image[:,:,0] < rgbThreshold[0]) \
| (image[:,:,1] < rgbThreshold[1]) \
| (image[:,:,2] < rgbThreshold[2])
等同于:
thresholds = (image[:,:,0] < rgbThreshold[0]) | (image[:,:,1] < rgbThreshold[1]) | (image[:,:,2] < rgbThreshold[2])
推荐阅读
- reactjs - 如何从 Firebase 存储下载图像并将它们作为道具分配给 React 中的文档?
- go - 有没有办法检查读取缓冲区是否剩余?
- docker - 在 Alpine docker 映像中找不到 stdint.h
- c# - 如何从相对路径加载c#中的json文件?
- uilabel - 如何显示从图像中随机抽取的数字?
- jdbc - 将驱动程序 Vertica JDBC 导入 FlyWay
- python - 一行中的相同值未附加到二维 Python 列表
- javascript - 如何截取 div 并将值插入模型的属性 ASP .NET Core
- mysql - 使用 Excel 单元格中的值作为 SQL 查询中 WHERE 子句的条件
- java - 如何解决 Maven Invoker API 警告:Maven 将以交互模式执行,但没有配置输入流