【发布时间】:2017-03-16 12:42:01
【问题描述】:
假设我有一个列表列表等......有一定深度:
ExampleNestedObject = numpy.ones(shape = (3,3,3,3,3))
一般我可以通过写来获得一个元素:
#Let:
#a, b, c, d, e -> are integers
print ExampleNestedObject[a][b][c][d][e]
#numpy also happens to allow:
print ExampleNestedObject[(a,b,c,d,e)]
#python in general allows:
print ExampleNestedObject[a,b,:,d,e]
我的问题是 -> 如何将索引“a,b,:,d,e”存储为对象?
SomeSliceChoice = a,b,:,d,e
print ExampleNestedObject[SomeSliceChoice]
【问题讨论】:
-
我在这里看到了这个问题的 numpy 特定版本:stackoverflow.com/questions/6795657/… 虽然我仍然对通用 python 解决方案感兴趣
-
numpy 数组不是列表。
-
该解决方案是通用的。
-
好的,我接受。我的问题是重复的,具有更好的 google-able 标题。
-
结果证明这个解决方案不适用于嵌套的 python 对象。见stackoverflow.com/questions/64419760
标签: python numpy indexing nested