【发布时间】:2013-03-28 07:20:27
【问题描述】:
我有一个形状为M x N x ... x T 的 Python numpy N 维数组,但直到运行时我才知道数组的维数(秩)。
如何创建该数组的子数组的视图,由两个具有长度等级的向量指定:extent 和 offset?
将 numpy 导入为 np
def select_subrange( orig_array, subrange_extent_vector, subrange_offset_vector ):
"""
returns a view of orig_array offset by the entries in subrange_offset_vector
and with extent specified by entries in subrange_extent_vector.
"""
# ???
return subarray
我被困住了,因为我发现的切片示例需要每个数组维度的 [ start:end, ... ] 条目。
【问题讨论】: