使用np.哪里()[0]

2024-09-30 00:37:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码检测所有低于阈值的点,然后定位起点和终点。在

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]

以后我真的不懂[0]的用法np.哪里()此处函数


Tags: 代码定位selfdatathresholdnpdiff阈值
2条回答
below = np.where(self.data < self.threshold)[0]

指:

take the first element from the tuple of ndarrays returned by np.where() and assign it to below.

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)的错误可能就是这一点。在

相关问题 更多 >

    热门问题