Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

python - VisibleDeprecationWarning: boolean index did not match indexed array along dimension 1; dimension is 2 but corresponding boolean dimension is 1

After an update of Macports, that I think updated numpy, I'm getting the warning:

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])

that was not raised before. The related code is:

# 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 is a single scalar.

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 
ight|`

    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

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I started getting a similar error after going up to numpy 1.10.1. I think you can get rid of the warning just by wrapping the boolean array in a numpy.where().

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

Since you're just taking the size, there's no need to use the pixels array, so this should work:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...