python - 可见弃用警告 : using a non-integer number instead of an integer will result in an error in the future

标签 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 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]

最佳答案

警告说不要使用 float 来索引你的数组;使用 np.int 而不是 np.floor

关于python - 可见弃用警告 : using a non-integer number instead of an integer will result in an error in the future,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39071480/

相关文章:

python - 高级切片。高阶切片/选择

python - 匹配两个 Python 列表的长度

python - 如何在 Python 中使用 dorpi5 或 dop853

python - Scipy 稀疏矩阵 - 不同实现的目的和用法

python - 在 Pandas Dataframe 中生成另一列的某些子集的最小值的新列的有效方法

python - del() 与 python 中的 del 语句

python - 从磁盘预取 numpy 数组?

python - 如何使用 Python 的 scipy.integrate.quad 评估多元函数的单积分?

python - 当需要符号表达式时,SymPy 输出数值结果

python - Matplotlib:如何水平显示图例元素?