当前位置:网站首页>numpy.ndarray不支持逻辑运算
numpy.ndarray不支持逻辑运算
2022-04-21 17:37:00 【王小希ww】
numpy.ndarray不支持逻辑运算
今天发现ndarray能实现算数运算,但不能实现逻辑运算
如果想掩盖掉>=3且<=6的部分,如下逻辑运算是会报错的:a >= 3 and a <= 6
a = np.array([1, 2, 3, 4, 5, 6, 7])
print(a >= 3 and a <= 6)
---
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
解决方法:用算数运算代替逻辑运算,即(a >= 3) * (a <= 6)
print(f"a >= 3 : {
a >= 3}")
print(f"a <= 6 : {
a <= 6}")
print(f"a >= 3 and a <= 6: {
(a >= 3) * (a <= 6)}")
print(f"range = {
(a >= 3) * (a <= 6) * a}")
输出结果:
a >= 3 : [False False True True True True True]
a <= 6 : [ True True True True True True False]
a >= 3 and a <= 6: [False False True True True True False]
range = [0 0 3 4 5 6 0]
版权声明
本文为[王小希ww]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_33934427/article/details/124304767
边栏推荐
- 胸部X光图像-数据集
- 【机器学习】门控循环单元
- Authentication bypass vulnerability in JIRA seraph (cve-2022-0540)
- short_open_tag 短开放标签 必须打开
- 手機日期插件 (轉加上自己喜歡的)
- Query the employee information of non business department employees who joined in 2021. Comrades, how to write SQL statements and solve them
- About the internal supposition
- 俄乌冲突引发顾虑 五眼网络安全部门建议盟友增强关键基础设施防护
- 检测、跟踪、行为识别All-In-One!产业级行人分析系统重磅开源!
- Arduino ESP8266当中的yield 函数
猜你喜欢
随机推荐
idea debug时提示”Method breakpoints may dramatically slow down debugging
我用Ehcache把查询性能提升了100倍,真香
@Transient
【栈】155. 最小栈
SSD_ RESNET aircraft and oil drum data set actual combat
redis实现乐观锁
什么是 ODBC – 开放式数据库连接
C# ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
剑指 Offer II 011. 0 和 1 个数相同的子数组
@Transient
Fixturlaser对中仪维修GO/NXA Pro/ECO/EVO系列
Ros2 abandonment guide 5: creating topic for ros2
We sincerely invite you to sign up for the first openharmony developer growth plan sharing day
Buuctf Web [WANGDING Cup 2018] Fakebook
No more simple intention lock
关于内推想说的
关于Riched32.dll木马
Spark SQL底层执行流程详解
Addition, deletion, modification and query of MySQL advanced table
BUUCTF WEB [网鼎杯 2018]Fakebook









