简体   繁体   English

使用 numpy argmax 在以下数组中查找大于 5 的值的第一次出现: arr = range(2, 20)

[英]Use numpy argmax to find the first occurrence of value greater than 5 in the following array: arr = range(2, 20)

Use numpy argmax to find the first occurrence of value greater than 5 in the following array: arr = range(2, 20)使用 numpy argmax 在以下数组中查找大于 5 的值的第一次出现: arr = range(2, 20)

import numpy as np

arr = np.array(range(2, 20))
idx = np.argmax(np.concatenate((arr[arr <= 5], [arr[arr > 5][0]])))

or或者

import numpy as np

arr = np.array(range(2, 20))
idx = np.argmax(arr[arr <= 5]) + 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Numpy 第一次出现大于现有值的值 - Numpy first occurrence of value greater than existing value Python pandas dataframe - 找到大于特定值的第一个匹配项 - Python pandas dataframe - find the first occurrence that is greater than a specific value 在nan之后的numpy数组中提取第一个匹配项 - extract the first occurrence in numpy array following the nan 首次出现的值大于numpy数组中给定的值 - first occurence of a value greater than given in numpy array 在 numpy 数组中查找第一次出现不是 X 或 Y 的某个值的索引 - Find the index of the first occurrence of some value that is not X or Y in a numpy array 使用矢量化在 Pandas dataframe 中查找大于当前值的价格值的第一次出现 - Find first occurrence of Price value which is greater than current value in Pandas dataframe using vectorization Numpy - 对于 array1 中的每个元素 X,在 array2 中找到大于 X 的第一个元素的索引 - Numpy - for each element X in array1 find index of first element greater than X in array2 查找 NumPy 数组中大于 N 的值的开始/停止索引范围 - Find Start / Stop Index Range For Values in NumPy Array Greater Than N 如何在numpy中找到二维数组的argmax? - How to find the argmax of a two dimensional array in numpy? 如何找到numpy数组中更大的最近值? - How to find nearest value that is greater in numpy array?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM