VisibleDeprecationWarning:布尔索引与维度1上的索引数组不匹配;维是2,但相应的布尔维是1 [英] VisibleDeprecationWarning: boolean index did not match indexed array along dimension 1; dimension is 2 but corresponding boolean dimension is 1

查看:778
本文介绍了VisibleDeprecationWarning:布尔索引与维度1上的索引数组不匹配;维是2,但相应的布尔维是1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Macports更新之后,我认为更新了numpy,我得到了警告:

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是单个标量.

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之后,我开始遇到类似的错误.我认为您可以通过将布尔数组包装在numpy.where()中来摆脱警告.

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

由于您只是在计算尺寸,因此无需使用pixels数组,因此应该可以使用:

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

这篇关于VisibleDeprecationWarning:布尔索引与维度1上的索引数组不匹配;维是2,但相应的布尔维是1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆