【发布时间】:2015-11-16 14:15:45
【问题描述】:
我正在从 Matlab/octve 切换到 Numpy/Scipy。
要选择 Matlab 数组的一段,这很容易。 例如
>> x = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12]
x =
1 2 3 4
5 6 7 8
9 10 11 12
>> y = x(2:3, 1:2)
y =
5 6
9 10
当
x = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
【问题讨论】:
-
您可以先查看关于数组索引的 numpy 文档,particularly the section on slice indexing