gpt4 book ai didi

python - Numpy 索引迭代器

转载 作者:太空宇宙 更新时间:2023-11-04 06:03:08 27 4
gpt4 key购买 nike

我不记得这是特定于 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] 会返回相应的值。有谁知道我说的是哪个迭代器?

最佳答案

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

关于python - Numpy 索引迭代器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23673299/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com