python - 创建带截止点的高斯
问题描述
我正在创建一个截止点为 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.
我究竟做错了什么?
解决方案
线
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
推荐阅读
- javascript - 结合2组JSON
- javascript - 在 JavaScript 中声明包含子对象的新变量是否有任何性能优势?
- java - MarkLogic Java API 异常抛出方法
- c# - 如何在 C# 中的 LDAP 中进行身份验证?
- javascript - 为每个用户输入分配一个数字
- android-studio - AVD 管理器错误:“无法找到 adb”
- sql-server - 使用存储过程搜索和插入数据(如果不存在)
- mysql - 在平均堆栈应用程序中存储用户的应用程序状态
- r - 按小时创建日期和时间向量
- gatsby - 如何在 URL 开头的 Gatsby 中创建动态路由