【发布时间】:2015-08-29 11:17:15
【问题描述】:
我在从 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。
【问题讨论】:
-
请创建一个最小的演示代码。 How to Ask
标签: python for-loop numpy indexing 2d