【发布时间】:2014-06-04 05:44:16
【问题描述】:
我正在尝试提取 numpy 数组的特定切片,但不知道如何用索引元组来表达它。如果索引的长度与维数相同,则使用索引元组有效:
ind = (1,2,3)
# these two values are the same
foo[1,2,3]
foo[ind]
但是如果我想在一个维度上得到一个切片,那么相同的符号就行不通了:
ind = (2,3)
# these two values are not the same
foo[:,2,3]
foo[:,ind]
# and this isn't even proper syntax
foo[:,*ind]
那么有没有办法将索引的命名元组与切片一起使用?
【问题讨论】: