草庐IT

python - 可见弃用警告 : boolean index did not match indexed array along dimension 1; dimension is 2 but corresponding boolean dimension is 1

coder 2023-08-23 原文

Macports 更新后,我认为更新了 numpy,我收到警告:

VisibleDeprecationWarning: boolean index did not match indexed array along dimension 1; dimension is 2 but corresponding boolean dimension is 1
  inliers = n.size(pixels[distances <= self.dst])

以前没有提出过。相关代码为:

# Compute distance of all non-zero points from the circumference 
distances = guess_feature.points_distance(pixels)

# Check which points are inliers (i.e. near the circle)
inliers = n.size(pixels[distances <= self.dst])

self.dst 是单个标量。

guess_feature.points_distance:

def points_distance(self,points):
    r'''
    Compute the distance of the points from the feature

    :math:`d = \left| \sqrt{(x_i - x_c)^2 + (y_i-y_c)^2} - r \right|`

    Args:
        points (numpy.ndarray): a (n,2) numpy array, each row is a 2D Point.

    Returns:
        d (numpy.ndarray): the computed distances of the points from the feature.

    '''

    xa = n.array([self.xc,self.yc]).reshape((1,2))
    d = n.abs(dist.cdist(points,xa) - self.radius)
    return d

有什么想法吗?

最佳答案

升级到 numpy 1.10.1 后,我开始遇到类似的错误。我认为您可以通过将 bool 数组包装在 numpy.where() 中来消除警告。

inliers = n.size(pixels[n.where(distances <= self.dst)])

因为您只是获取大小,所以不需要使用像素数组,所以这应该可行:

inliers = n.size(n.where(distances <= self.dst])[0])

关于python - 可见弃用警告 : boolean index did not match indexed array along dimension 1; dimension is 2 but corresponding boolean dimension is 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33098765/

有关python - 可见弃用警告 : boolean index did not match indexed array along dimension 1; dimension is 2 but corresponding boolean dimension is 1的更多相关文章

随机推荐