numpy.argwhere 对于 numpy.ndarray 的替代函数是什么?

What is an alternative function for numpy.argwhere for numpy.ndarray?

我想定位单色图像的局部最大值。 图像是 numpy.ndarray,数据类型为 uint8。

图像中有几个最大值为255的点,所以我打算取位置的平均值来找到最大值的有效位置。

对于正常的 numpy.array,下面的代码将有效地 return 我的值等于 255 的元素的位置。

positions = numpy.unravel_index(image.argwhere(), image.shape)

其中图像是 numpy.array 对象。但是在我的代码中,图像是一个 numpy.ndarray 对象,导致我收到以下错误:

AttributeError: 'numpy.ndarray' object has no attribute 'argwhere'

是否有适用于 numpy.ndarray 的 'argwhere' 替代函数?

argwhere 是 numpy 库的一个函数,它应该像

np.argwhere(image)

无论如何,np.array不是一个单独的类型,它只是另一种创建np.ndarray的方法。 在任何你喜欢的 numpy 数组变量上尝试 type,它总是 np.ndarray.