Python VisibleDepractionWarning:使用非整数而不是整数将导致将来出现错误
运行包含以下函数的python程序时,Python VisibleDepractionWarning:使用非整数而不是整数将导致将来出现错误,python,numpy,scipy,Python,Numpy,Scipy,运行包含以下函数的python程序时,image[x,y]=0会给出以下错误消息。这意味着什么?如何解决?谢谢 警告 VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future image[x,y] = 0 Illegal instruction (core dumped) 代码 def创建图像和标签(nx,ny): x=
image[x,y]=0
会给出以下错误消息。这意味着什么?如何解决?谢谢
警告
VisibleDeprecationWarning: using a non-integer number instead of an integer
will result in an error in the future
image[x,y] = 0
Illegal instruction (core dumped)
代码
def创建图像和标签(nx,ny):
x=np.楼层(np.随机随机随机随机数(1)[0]*nx)
y=np.楼层(np.随机随机随机数(1)[0]*ny)
图像=np.ones((nx,ny))
标签=np.ones((nx,ny))
图像[x,y]=0
图像距离=nImage.形态学.distance\u transform\u edt(图像)
r=np.random.rand(1)[0]*(r_max-r_min)+r_min
平台=np.random.rand(1)[0]*(平台最大值-平台最小值)+平台最小值
标签[image_distance r]=1
标签=(1-标签)
图像距离[图像距离r]=1
图像距离=(1-图像距离)*平台
图像=图像距离+np.random.randn(nx,ny)/sigma
返回图像,标签[92:nx-92,92:nx-92]
警告是不要使用浮点数索引数组;使用np.int
而不是np.floor
哪个版本的numpy
/scipy
?我刚刚测试过,numpy版本是1.11.0;scipy版本是0.17.1np。floor
为您提供了一个浮点,但将来只能使用整数进行索引。因此,您会收到一条弃用警告,指出numpy
的版本升级将在将来破坏您的代码。但此警告不应导致错误。您是否单独尝试过这一部分,即仅创建图像数组并将一个元素设置为零?
def create_image_and_label(nx,ny):
x = np.floor(np.random.rand(1)[0]*nx)
y = np.floor(np.random.rand(1)[0]*ny)
image = np.ones((nx,ny))
label = np.ones((nx,ny))
image[x,y] = 0
image_distance = ndimage.morphology.distance_transform_edt(image)
r = np.random.rand(1)[0]*(r_max-r_min)+r_min
plateau = np.random.rand(1)[0]*(plateau_max-plateau_min)+plateau_min
label[image_distance <= r] = 0
label[image_distance > r] = 1
label = (1 - label)
image_distance[image_distance <= r] = 0
image_distance[image_distance > r] = 1
image_distance = (1 - image_distance)*plateau
image = image_distance + np.random.randn(nx,ny)/sigma
return image, label[92:nx-92,92:nx-92]