【问题标题】:Numpy Index IteratorNumpy 索引迭代器
【发布时间】:2014-05-15 08:44:36
【问题描述】:

我不记得这是 Python 还是 numpy 特定的。我曾经找到一个不在主要介绍中的索引迭代器,但是我尝试寻找它,但我再也找不到它了。这就是它给我的:

>>> foo = ones((1,2,3))

>>> for i in foo.getThisMagicIteratorIndexThiny():
>>>     print i
(0,0,0)
(0,0,1)
(0,0,2)
(0,1,0)

而且,foo[i] 将返回相应的值。有谁知道我说的是哪个迭代器?

【问题讨论】:

  • 你可以使用for idx in np.ndindex(foo.shape):
  • 完美。如果您添加答案,我们可以关闭它。

标签: python numpy iterator


【解决方案1】:

根据flebool的评论,解决方案是使用for idx in np.ndindex(foo.shape):

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 2014-01-15
    相关资源
    最近更新 更多