我在从2d查找索引时遇到问题np.array()
。使用If循环,对于我的算法而言,计算时间过长。我需要一个numpy函数来从任何数组中找到索引。该函数np.where()
对我没有帮助。.这是一个抽象:
>>> conditions = [[0 0 0 0 4]
[0 0 0 0 3]
[0 0 0 0 2]
...,
[2 1 3 4 2]
[2 1 3 4 1]
[2 1 3 4 0]]
>>> a = [0, 0, 0, 0, 2]
>>> index = np.where(conditions==a)
如果我使用它,尽管我有列和行索引,但是我无法解释它们。例如,我需要具体的索引值index = 2
。
>>> np.where((conditions == a).all(axis=1))[0]
array([2])
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句