首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用np.where()[0]

使用np.where()[0]
EN

Stack Overflow用户
提问于 2018-10-04 14:44:31
回答 2查看 5.7K关注 0票数 3

我的代码检测阈值下的所有点,然后定位起始点和结束点。

代码语言:javascript
复制
below = np.where(self.data < self.threshold)[0]


startandend = np.diff(below)
startpoints = np.insert(startandend, 0, 2)
endpoints = np.insert(startandend, -1, 2)
startpoints = np.where(startpoints>1)[0]
endpoints = np.where(endpoints>1)[0]
startpoints = below[startpoints]
endpoints = below[endpoints]

在这里,我不太懂after np.where()函数的用法。

EN

回答 2

Stack Overflow用户

发布于 2018-10-04 15:06:56

代码语言:javascript
复制
below = np.where(self.data < self.threshold)[0]

指:

从np.where()返回的ndarray元组中获取第一个元素,并将其分配给below

票数 1
EN

Stack Overflow用户

发布于 2018-11-15 19:35:22

np.where是很棘手的。它返回一个数组,该数组包含满足条件的索引的列表,即使条件从未满足。特别是在np.where(my_numpy_array==some_value)[0]的情况下,这意味着您需要数组中的第一个值,它是一个列表,它包含条件满足单元格的索引列表。

一口大口。简单地说,np.where(array==x)[0]返回满足条件的索引列表。我猜这是为广泛的应用程序设计numpy的结果。

请记住,没有匹配仍然返回空列表;可能会导致像only size-1 arrays can be converted to python (some type)这样的错误。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52649568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档