2024-10-01 04:52:28 发布
网友
假设我有:
numpy.random.seed(20) a=numpy.random.rand(5000) b=numpy.random.rand(5000)
我想得到wherea[x] > b[x]的索引,即所有x的索引
a[x] > b[x]
此外,我想得到where(a[x-1] < b[x-1]) && (a[x] > b[x])的索引。在
(a[x-1] < b[x-1]) && (a[x] > b[x])
有人能帮忙吗?我有一种感觉,我必须使用屏蔽数组,但我不太明白如何使用。在
首先,使用numpy.where:
numpy.where
>>> numpy.where(a>b) (array([ 0, 1, 2, ..., 4993, 4994, 4999]),)
你可以从第二个开始
但你必须分开处理。在
又一次,@askewchan带着正确的第二个表达式来了,而我没有正确地添加1:)
>>> np.where((a[1:] > b[1:]) & (a[:-1] < b[:-1]))[0] + 1 array([ 5, 9, 17, ..., 4988, 4991, 4999])
首先,使用
numpy.where
:你可以从第二个开始
^{pr2}$但你必须分开处理。在
又一次,@askewchan带着正确的第二个表达式来了,而我没有正确地添加1:)
相关问题 更多 >
编程相关推荐