python - 比较两个不同大小的数组,按元素?
问题描述
假设我有两个不同大小的数组:
In [79]: tr
Out[79]: array([1, 1, 0, 6, 0, 3])
In [80]: br
Out[80]: array([ 9, 26, 24, 18, 14, 12, 8])
我想确保 br 的所有元素都大于 tr 的所有元素,即 br > tr
ValueError: operands could not be broadcast together with shapes (6,) (7,)
解决方案
您可以简单地检查 br 中的最小数字是否大于 tr 中的最大数字:
if min(br) > max(tr):
# all the element in br are bigger
else:
# there is at least one value in tr bigger or equal than one value in br
推荐阅读
- spring-boot - Gradle 多模块项目 java.lang.NoClassDeffFoundError
- dependencies - 如何在不覆盖依赖项的情况下安装 Chocolatey 包?
- javascript - 基于 NativeScript Vue Auth 的导航
- reactjs - 将 url 参数传递给 react-router 的 Link 组件的正确方法是什么?
- reactjs - 部署后 Netlify 上未显示最新更改
- node.js - Nodejs并发请求覆盖变量
- android - 安全异常 App.Utils.getDeviceSerial 错误。如何解决?
- reactjs - 导航时反应本机组件安装问题
- android - android studio 中的倒计时
- java - 将多个 pdf 文件上传到 Firebase 存储 - Android