Python存储切片索引作为对象

时间:2016-11-03 02:27:51

标签: python numpy indexing nested

说我有一份列表清单......等等......深度:

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]

1 个答案:

答案 0 :(得分:1)

诀窍是将索引对象视为切片对象的元组。

例1:

<IfModule mod_php5.c>
php_value post_max_size 200M
php_value upload_max_filesize 200M
php_value memory_limit 300M
php_value max_execution_time 259200
php_value max_input_time 259200
php_value session.gc_maxlifetime 1200
</IfModule>

例2:

Object[1,2,:] == Object[(1,2,slice(None,None,None))]

请注意&#39;&#39;&#39;切片:

的语法
WantedSliceObject = (1,2,slice(None,None,None), 4,5)
Object[1,2,:,4,5] == Object[WantedSliceObject]