【发布时间】:2018-07-09 04:47:04
【问题描述】:
我阅读了类似的主题here。我认为问题有所不同,或者至少.index() 无法解决我的问题。
这是 R 中的一个简单代码及其答案:
x <- c(1:4, 0:5, 11)
x
#[1] 1 2 3 4 0 1 2 3 4 5 11
which(x==2)
# [1] 2 7
min(which(x==2))
# [1] 2
which.min(x)
#[1] 5
它只是返回满足条件的项目的索引。
如果x 是Python 的输入,我怎样才能得到满足条件x==2 和数组which.min 中最小的元素的索引。
x = [1,2,3,4,0,1,2,3,4,11]
x=np.array(x)
x[x>2].index()
##'numpy.ndarray' object has no attribute 'index'
【问题讨论】: