【问题标题】:Index of an array from a 2d np.array in Python? [duplicate]Python中二维np.array的数组索引? [复制]
【发布时间】: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


【解决方案1】:
>>> np.where((conditions ==  a).all(axis=1))[0]
array([2])

【讨论】:

  • 谢谢。 :) 解决方案帮帮我!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-12
  • 2015-09-06
  • 2023-03-07
  • 2020-07-30
  • 1970-01-01
  • 2021-11-10
相关资源
最近更新 更多