2015-10-13 77 views
7

的MacPorts的更新之後,我認爲更新numpy的,我得到了警告:VisibleDeprecationWarning:布爾型索引與維度1中的索引數組不匹配;尺寸爲2,但相應的布爾尺寸爲1

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 

任何想法?

回答

12

在numpy 1.10.1之後我開始出現類似的錯誤。我想你可以通過將布爾數組包裝在numpy.where()中來擺脫警告。

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

既然你只是把大小,有沒有必要使用像素陣列,所以這應該工作:

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