python - numpy.ndarray 的 numpy.argwhere 的替代函数是什么?
问题描述
我想定位单色图像的局部最大值。该图像是一个 numpy.ndarray,dtype 为 uint8。
图像有几个点的最大值为 255。因此我打算取位置的平均值来找到最大值的有效位置。
对于普通的 numpy.array,以下代码将有效地返回值等于 255 的元素的位置。
positions = numpy.unravel_index(image.argwhere(), image.shape)
其中 image 是 numpy.array 对象。但是在我的代码中, image 是一个 numpy.ndarray 对象,导致我收到以下错误:
AttributeError: 'numpy.ndarray' object has no attribute 'argwhere'
'argwhere' 是否有适用于 numpy.ndarray 的替代功能?
解决方案
argwhere
是 numpy 库的一个函数,它应该像
np.argwhere(image)
无论如何,np.array
它不是一个单独的类型,它只是另一种创建np.ndarray
. 尝试type
任何你喜欢的 numpy-array 变量,它总是一个np.ndarray
.
推荐阅读
- ansible - 需要ansible playbook来比较Linux上从一台服务器到另一台服务器的文件
- sql - 如何用前一行的值填充空列?
- c++ - SQLite3插入语句错误,但错误消息为空白?
- php - 样式和下拉菜单不见了
- python - 如何通过 Python 从列表中创建 TreeNode
- azure - 在 Azure 中为 ML Insights and Actions 设计云原生应用程序
- javascript - 在 macOS High Sierra (10.13.6) 上使用 R (v3.6.0) 中的 PhantomJS 进行 Webscraping Javascript 表返回部分表
- javascript - 在 Postman 中解析 JSON 数组
- api - 为什么在输入地址上使用 getPlace() 时谷歌自动完成返回未定义
- git - gitlab-ci.yml 仅在受保护的分支上运行作业