【发布时间】:2020-08-17 17:10:08
【问题描述】:
我有读取和显示 SEGY 地震数据的工作代码。功能版本太大,无法在此处粘贴。我遇到的问题在于以下部分。
#find traces indices that belong to Inline x
CXline=self.Line_box.text() #Get chosen line from Gui textbox
if CXline=="": #If empty, use all inline indices
inds=np.where(inlines)[0]
else:
inds=np.where(inlines==(CXline))[0] #load data for specific inline indices.
如果 Line_box(QT 文本编辑框)为空,“if”部分按预期工作,“inds”输出数组正确,代码继续运行。
如果我在 Line_box 中输入一个数字(例如 425),我希望在 np.where 函数中使用该数字但它不起作用,它只是输出一个空数组并且代码停止.我还收到以下消息(尽管它是导致崩溃的空数组)。
Warning (from warnings module):
File "/Users/willhutchins/Documents- Offline/Python/Synth_Seismic/SEGY View/SEGY_Viewer.py", line 269
inds=np.where(inlines==(str(CXline)))[0]
FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
如果我手动在代码中键入一个数字,代码会按预期运行,因此这肯定与 np.where 如何理解来自 Line_box 的输入有关。我假设我的语法错误或需要将 Line_box 输入转换为不同的 dtype。
else:
inds=np.where(inlines==425)[0]
【问题讨论】:
-
where只返回其参数的真/非零元素的索引。因此,您必须首先获得inlines==425或任何正确的信息。解释一下inlines和CXline是什么。
标签: python macos numpy where-clause