首页 > 解决方案 > 创建带截止点的高斯

问题描述

我正在创建一个截止点为 e^(-2) 的高斯图像,但我一直遇到错误。我已经定义了我的高斯分布,我正在尝试使它具有布尔返回值,但它不起作用。

import numpy as np
import scipy.misc


sizex=684
sizey=608

X = np.linspace(-sizex/2,sizex/2,sizex)
Y = np.linspace(-sizey/2,sizey/2,sizey)
xx, yy = np.meshgrid(X, Y, sparse=True)

def Gauss(xx,yy,centx,centy,sig):

    return 1/np.exp(((xx-centx)**2+(yy-centy)**2)/sig**2) > 1/np.exp(2)

t=Gauss(xx,yy,0,0,100)

scipy.misc.imsave('e6.bmp',t)

我不断收到以下错误:TypeError: numpy boolean subtract, -operator, is deprecated, use the bitwise_xor, ^operator, or the logical_xor function instead.

我究竟做错了什么?

标签: pythongaussian

解决方案


线

return 1/np.exp(((xx-centx)**2+(yy-centy)**2)/sig**2) > 1/np.exp(2)

如果上述不等式成立,则返回 1(真),否则返回 0。

如果您想将这些值设置为 0,则应使用赋值:

result = 1/np.exp(((xx-centx)**2+(yy-centy)**2)/sig**2)
result[result <= 1/np.exp(2)] = 0
return result

推荐阅读