【问题标题】:Find Position of Nth place within numpy array? [duplicate]在numpy数组中查找第N个位置的位置? [复制]
【发布时间】:2019-09-28 22:28:50
【问题描述】:

给定二维静态 numpy 数组中的第 n 个位置,我应该如何计算该点在所述数组中的位置?例如,给定数字 5 表示第 n 个位置,数组形状为 (4, 2),我想接收数组中第 n 个位置所在的位置,即位置 (0, 1)。 10 的数组形状中的第 5 位,1 对应位置 (5, 0),依此类推。

有没有我可以使用的 numpy 函数?

【问题讨论】:

  • numpy.unravel_index?

标签: python-3.x numpy numpy-ndarray


【解决方案1】:

不清楚你的意思,试试numpy.argwhere(...)

来自 numpy 文档:


    >>> x = np.arange(6).reshape(2,3)
    >>> x
    array([[0, 1, 2],
           [3, 4, 5]])
    >>> np.argwhere(x>1)
    array([[0, 2],
           [1, 0],
           [1, 1],
           [1, 2]])

【讨论】:

  • 不是我想要的。请参阅编辑以获取更多说明。 :)
猜你喜欢
  • 2012-09-07
  • 2020-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-24
  • 2013-06-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多